gcc 4.8.0 20120930 (experimental) compiled with the flags -Wall -pedantic -std=c++11 rejects the following code: //---------------- lass nullable_int { bool init_; union { unsigned char for_value_init; int value_; }; public: constexpr nullable_int() : init_(false), for_value_init() {} }; //---------------- "main.cpp||In constructor 'constexpr nullable_int::nullable_int()':| main.cpp|9|error: uninitialized member 'nullable_int::<anonymous>' in 'constexpr' constructor|" This prevents a very reasonable use-case, namely the creation of a literal type that contains an anonymous union member.
(In reply to comment #0) Some copy'n-paste error occurred while attempting to format the code example. The correct code under investigation was: //---------------- class nullable_int { bool init_; union { unsigned char for_value_init; int value_; }; public: constexpr nullable_int() : init_(false), for_value_init() {} }; //----------------
Related to PR54768.
Related to PR51675.
On it.
Author: paolo Date: Tue Oct 23 23:43:21 2012 New Revision: 192749 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192749 Log: /cp 2012-10-23 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54922 * semantics.c (cx_check_missing_mem_inits): Handle anonymous union members. /testsuite 2012-10-23 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54922 * g++.dg/cpp0x/constexpr-union4.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog
Fixed for 4.8.0.
Patch is reverted for now. The fix wasn't correct (or was incomplete), as showed by the testcase: class nullable_int { bool init_; union { unsigned char for_value_init; int value_; }; public: constexpr nullable_int() : init_(false), for_value_init() {} }; int main() { nullable_int n; }
Author: paolo Date: Wed Nov 7 11:15:40 2012 New Revision: 193292 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193292 Log: /cp 2012-11-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/55226 Revert: 2012-10-23 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54922 * semantics.c (cx_check_missing_mem_inits): Handle anonymous union members. /testsuite 2012-11-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/55226 Revert: 2012-10-23 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54922 * g++.dg/cpp0x/constexpr-union4.C: New. Removed: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog
*** Bug 55226 has been marked as a duplicate of this bug. ***
*** Bug 56215 has been marked as a duplicate of this bug. ***
Author: jason Date: Fri Feb 15 01:27:47 2013 New Revision: 196070 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196070 Log: PR c++/54922 * semantics.c (build_anon_member_initialization): New. (build_data_member_initialization): Use it. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-union5.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c
Fixed.
*** Bug 54768 has been marked as a duplicate of this bug. ***
*** Bug 56583 has been marked as a duplicate of this bug. ***