Bug 52707 - [C++11] Deleted special member function prevent type being an aggregate
Summary: [C++11] Deleted special member function prevent type being an aggregate
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-03-25 14:08 UTC by Daniel Krügler
Modified: 2018-09-22 03:36 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-04-13 00:00:00


Attachments
partial patch (502 bytes, patch)
2012-04-15 17:15 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2012-03-25 14:08:50 UTC
gcc 4.8.0 20120318 (experimental) in C++11 mode rejects the following code:

//---
struct A {
 int m;
 A() = delete;
};

A a = {1}; // line 6
//---

"6|error: could not convert '{1}' from '<brace-enclosed initializer list>' to 'A'|"

But according to N3290 (N3376 still the same) the user-declared, deleted default-constructor should not prevent A from being an aggregate type and aggregate initialization should happen here. The error text implies that A is considered as a non-aggregate and no feasible constructor is found.

According to 8.4.2 p4:

"A function is user-provided if it is user-declared and not explicitly
defaulted or deleted on its first declaration."

and by 8.5.1 p1:

"An aggregate is [..] a class (Clause 9) with no user-provided constructors"

Thus, the deleted default constructor is not a user-provided constructor and aggregate initialization should work.

This is due to DR 1135 which is already part of C++11:

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1135
Comment 1 Jason Merrill 2012-04-15 17:15:40 UTC
Created attachment 27161 [details]
partial patch

This patch fixes the bug, but breaks several other tests in the testsuite, because many places in the compiler assume that if the constructor isn't callable, it's also non-trivial.  This needs to be fixed, but for the moment I'm going to look at lower-hanging fruit.
Comment 2 Paolo Carlini 2013-12-09 09:36:34 UTC
This is fixed in mainline. I'm adding the testcase and closing the bug.
Comment 3 paolo@gcc.gnu.org 2013-12-09 09:50:53 UTC
Author: paolo
Date: Mon Dec  9 09:50:51 2013
New Revision: 205801

URL: http://gcc.gnu.org/viewcvs?rev=205801&root=gcc&view=rev
Log:
2013-12-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/52707
	* g++.dg/cpp0x/deleted2.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/deleted2.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2013-12-09 09:52:57 UTC
Done.