Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultConstructible does not guarantee nullary copy-list-initialization #236

Closed
potswa opened this issue Nov 21, 2013 · 3 comments
Closed

Comments

@potswa
Copy link

potswa commented Nov 21, 2013

DefaultConstructible requires T x(), T x{}, T() and T{} be valid statements but says nothing about T x = {} , a.k.a. copy-list-initialization. This is the semantic used to initialize a function parameter from an empty list argument.

Copy-list-initialization will not call an explicit constructor (13.3.1.7 [over.match.list]), which is not otherwise required by DefaultConstructible. The standard containers have such explicit default constructors (specifically, would-be conversion constructors with default argument).

Therefore, this is invalid:

void f( std::vector< int > ) {}
f( {} );

As far as I've seen, only GCC 4.9 rejects this; Clang and GCC up to 4.8 accept it.

The specific problem with containers as illustrated may be considered a separate defect.

@sdutoit
Copy link
Contributor

sdutoit commented Nov 21, 2013

Hi David,

This doesn't sound like an editorial issue. It's probably a CWG issue - you can check the CWG active issues list or Richard might chime in here.

Thanks,

Stefanus


Stefanus Du Toit

On Thu, Nov 21, 2013 at 4:09 AM, David Krauss notifications@github.com
wrote:

DefaultConstructible requires T x(), T x{}, T() and T{} be valid statements but says nothing about T x = {} , a.k.a. copy-list-initialization. This is the semantic used to initialize a function parameter from an empty list argument.
Copy-list-initialization will not call an explicit constructor (13.3.1.7 [over.match.list]), which is not otherwise required by DefaultConstructible. The standard containers have such explicit default constructors (specifically, would-be conversion constructors with default argument).
Therefore, this is invalid:
void f( std::vector< int > ) {}
f( {} );
As far as I've seen, only GCC 4.9 rejects this; Clang and GCC up to 4.8 accept it.

The specific problem with containers as illustrated may be considered a separate defect.

Reply to this email directly or view it on GitHub:
#236

@jwakely
Copy link
Member

jwakely commented Nov 21, 2013

There's a library issue opened by Richard to make the container default constructors non-explicit, and I'm going to fix gcc 4.9 so the constructors are not explicit. They never should have been explicit and gcc should not have changed them.

@jwakely
Copy link
Member

jwakely commented Nov 25, 2013

http://cplusplus.github.io/LWG/lwg-active.html#2193 is the issue I was referring to.

@potswa potswa closed this as completed Jun 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants