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 04/28/2015 07:25 PM, Jonathan Wakely wrote:
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).

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.

Ah, hadn't been aware of DR 253.  Makes sense.

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.

Turns out there are three places in LibreOffice that use such empty const vectors (to pass into a function that takes a vector const& argument, or to verbosely return an empty vector from a function, [1][2]), but of course no problem to put explicit initializers there.

[1] <http://cgit.freedesktop.org/libreoffice/core/commit/?id=aef1826d9ca318a1359a2116e7f146e993413234> [2] <http://cgit.freedesktop.org/libreoffice/core/commit/?id=aef1826d9ca318a1359a2116e7f146e993413234>


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