Opened 5 years ago

Closed 5 years 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:

Description

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(

#if BOOST_WORKAROUND(__IBMCPP__,<=600)
    /* 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::
        ctor_args_list(),
    const allocator_type& al=
      typename mpl::identity<multi_index_container>::type::
        allocator_type()):
#else
    const ctor_args_list& args_list=ctor_args_list(),
    const allocator_type& al=allocator_type()):
#endif

    bfm_allocator(al),
    super(args_list,bfm_allocator::member),
    node_count(0)
  {
    BOOST_MULTI_INDEX_CHECK_INVARIANT;
}

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

Change History (1)

comment:1 by Joaquín M López Muñoz, 5 years ago

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