Bug 49132 - [DR 178] Aggregate-initialization rejected for class with const data member
Summary: [DR 178] Aggregate-initialization rejected for class with const data member
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 61581 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-05-23 21:20 UTC by Daniel Krügler
Modified: 2014-06-26 17:00 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95, 3.0, 4.0.4, 4.6.0, 4.7.0
Last reconfirmed: 2011-05-23 22:07:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2011-05-23 21:20:46 UTC
gcc 4.7.0 20110521 (experimental) in C++0x mode rejects the following code:

//---
struct A {
 const int m;
};

A a1 = {}; // #1
A a2{};    // #2
//---

The error messages at the lines marked with #1 and #2 are:

"error: uninitialized const member 'A::m'"

The code should be accepted, because the objects undergo aggregate-initialization. The error message is incorrect, the objects are initialized.
Comment 1 Jason Merrill 2011-05-23 22:07:23 UTC
Yes.  process_init_constructor_record shouldn't complain about uninitialized const members, because within aggregate initialization, members without explicit initializers are value-initialized.  Fabien?
Comment 2 Jason Merrill 2011-05-23 22:08:46 UTC
It's annoying how GCC bugzilla tends not to send mail to people when I add them to CC even if I also add a comment.  Anyway, Fabien, please take a look at this bug.
Comment 3 Jason Merrill 2011-05-23 22:11:49 UTC
This is a regression relative to 4.5 in C++98/03 mode as well (the a1 declaration).
Comment 4 Jason Merrill 2011-05-23 22:14:39 UTC
Actually it isn't a regression, it's broken as far back as 2.95.
Comment 5 Jason Merrill 2011-05-23 22:17:51 UTC
This was clarified to be well-formed as part of DR 178.

http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#178
Comment 6 Jonathan Wakely 2011-05-23 23:16:02 UTC
(In reply to comment #2)
> It's annoying how GCC bugzilla tends not to send mail to people when I add them
> to CC even if I also add a comment.  Anyway, Fabien, please take a look at this
> bug.

GCC bugzilla mails seem to go out in random order with arbitrarily long delays recently, so the "New" bug mail sometimes appears in the archives several minutes after the first comment on a bug. very annoying
Comment 7 Paolo Carlini 2014-06-24 18:41:36 UTC
Mine.
Comment 8 paolo@gcc.gnu.org 2014-06-25 14:28:08 UTC
Author: paolo
Date: Wed Jun 25 14:27:35 2014
New Revision: 211981

URL: https://gcc.gnu.org/viewcvs?rev=211981&root=gcc&view=rev
Log:
/cp
2014-06-25  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 178
	PR c++/49132
	* typeck2.c (process_init_constructor_record): Do not complain about
	uninitialized const members, because within aggregate-initialization,
	members without explicit initializers are value-initialized.

/testsuite
2014-06-25  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 178
	PR c++/49132
	* g++.dg/cpp0x/aggr1.C: New.
	* g++.dg/cpp0x/aggr2.C: Likewise.
	* g++.dg/init/aggr11.C: Likewise.
	* g++.dg/init/aggr12.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/aggr1.C
    trunk/gcc/testsuite/g++.dg/cpp0x/aggr2.C
    trunk/gcc/testsuite/g++.dg/init/aggr11.C
    trunk/gcc/testsuite/g++.dg/init/aggr12.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck2.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Paolo Carlini 2014-06-25 14:29:35 UTC
Fixed for 4.10.0.
Comment 10 Paolo Carlini 2014-06-26 17:00:37 UTC
*** Bug 61581 has been marked as a duplicate of this bug. ***