Opened 8 months ago

Closed 8 months ago

#13518 closed Bugs (fixed)

Default constructor is explicit, no reason to be.

Reported by: anonymous Owned by: Joaquín M López Muñoz
Milestone: To Be Determined Component: multi_index
Version: Boost 1.66.0 Severity: Problem
Keywords: Cc:


See the follwing code

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>

using namespace std;

struct aggregate {
        boost::multi_index_container<int> a;

int main()
        using boost::multi_index_container;
        multi_index_container<int> a; // default init
        // multi_index_container<int> b(); // NOT A THING, not object init
        multi_index_container<int> c =
                multi_index_container<int>(); //value init + (elided) copy

        auto d = multi_index_container<int>(); // value init + (elided) copy

        multi_index_container<int> e{}; // direct-list-init, chooses value init

        auto f = multi_index_container<int>{};
        // direct-list-init, chooses value init
        // followed by elided copy

        multi_index_container<int> g = {}; // ERROR
        // copy-list-init, should choose value init
        // but fails becase default constructor is explicit

        aggregate agg1{};    // ERROR for the same reason above
        aggregate agg2 = {}; // ERROR for the same reason above
        // Does aggregate init which does copy-list-init on members that
        // were not specified in the list.
        auto agg3 = aggregate(); //OK, value init

        multi_index_container<int> h{1, 2, 3, 4};
        // direct-list-init, chooses initializer list

        multi_index_container<int> i = {1, 2, 3, 4};
        // copy-list-init, chooses initializer list
        return 0;

The problematic ctor is in line 175 of multi_index_container.hpp

  explicit multi_index_container(

    /* VisualAge seems to have an ETI issue with the default values
     * for arguments args_list and al.

    const ctor_args_list& args_list=
      typename mpl::identity<multi_index_container>::type::
    const allocator_type& al=
      typename mpl::identity<multi_index_container>::type::
    const ctor_args_list& args_list=ctor_args_list(),
    const allocator_type& al=allocator_type()):


Probably, it was made explicit for the case when it is called with non-default parameters.

Change History (1)

comment:1 Changed 8 months ago by Joaquín M López Muñoz

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.