This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::__debug::vector default ctor must not be defaulted
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Stephan Bergmann <sbergman at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Tue, 28 Apr 2015 18:25:42 +0100
- Subject: Re: std::__debug::vector default ctor must not be defaulted
- Authentication-results: sourceware.org; auth=none
- References: <553FAA55 dot 7020607 at redhat dot com>
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.