This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::__debug::vector default ctor must not be defaulted


On 28/04/15 17:42 +0200, Stephan Bergmann wrote:
I think

#if __cplusplus < 201103L
     vector() _GLIBCXX_NOEXCEPT
     : _Base() { }
#else
     vector() = default;
#endif

(libstdc++-v3/include/debug/vector) introduced with r210123 (present in GCC 5 and trunk) is wrong. The standard mandates that the std::vector default ctor is user-provided ([vector.overview] "vector() noexcept : vector(Allocator()) { }"), and defaulting it breaks code like

 const std::vector< double > aDXArray;

because of [dcl.init] "If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor." (as flagged at least by trunk Clang).

(Repeating what I said offlist)

See the notes about DR 253 at https://gcc.gnu.org/gcc-4.6/changes.html
which explains why GCC accepts it. The expectation is that Clang will
start accepting it at some point too.

I'm not convinced it's worth changing anything here.

The main advantage of defaulting the constructor is that we don't have
to restate the exception specification on the debug vector.

The disadvantage is that you can't compile almost useless code (an
empty vector that can never be modified to be non-empty) without
adding an explicit initializer.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]