G++ erroneously compiles this code: struct { struct { int& i ; } bar ; } foo ; which should caues an error because the implicitly generated constructor for foo.bar cannot initialize foo.bar.i .
Confirmed. Not even a warning is given with -W -Wall. This is a regression in 3.3, 3.4 and mainline, because up to 3.2 we get this: g/x> /home/bangerth/bin/gcc-3.2*/bin/c++ -c x.cc -W -Wall -Wunused x.cc:1: warning: non-static reference `int&<anonymous struct>::<anonymous struct>::i' in class without a constructor W.
The code is actually ill-formed.
Subject: Bug 14401 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: mmitchel@gcc.gnu.org 2004-03-09 07:27:26 Modified files: gcc/cp : ChangeLog class.c init.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/ext: anon-struct4.C gcc/testsuite/g++.dg/init: ctor3.C union1.C Log message: PR c++/14401 * class.c (check_field_decls): Complain about non-static data members of reference type in unions. Propagate CLASSTYPE_REF_FIELDS_NEED_INIT and CLASSTYPE_READONLY_FIELDS_NEED_INIT from the types of non-static data members. * init.c (perform_member_init): Complain about mbmers with const type that are not explicitly initialized. PR c++/14401 * g++.dg/init/ctor3.C: New test. * g++.dg/init/union1.C: New test. * g++.dg/ext/anon-struct4.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.72&r2=1.3892.2.73 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.595.4.6&r2=1.595.4.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.356.2.6&r2=1.356.2.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.131&r2=1.3389.2.132 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/anon-struct4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/union1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 14401 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-03-09 08:16:49 Modified files: gcc/cp : ChangeLog class.c cp-tree.h decl.c init.c lex.c name-lookup.c name-lookup.h ptree.c search.c typeck.c gcc/testsuite : ChangeLog gcc/testsuite/g++.dg/lookup: koenig1.C used-before-declaration.C gcc/testsuite/g++.dg/other: do1.C gcc/testsuite/g++.dg/overload: koenig1.C gcc/testsuite/g++.dg/parse: crash13.C gcc/testsuite/g++.dg/template: instantiate3.C Added files: gcc/testsuite/g++.dg/ext: anon-struct4.C gcc/testsuite/g++.dg/init: ctor3.C union1.C Log message: PR c++/14401 * class.c (check_field_decls): Complain about non-static data members of reference type in unions. Propagate CLASSTYPE_REF_FIELDS_NEED_INIT and CLASSTYPE_READONLY_FIELDS_NEED_INIT from the types of non-static data members. * init.c (perform_member_init): Complain about mbmers with const type that are not explicitly initialized. PR c++/14401 * g++.dg/init/ctor3.C: New test. * g++.dg/init/union1.C: New test. * g++.dg/ext/anon-struct4.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3987&r2=1.3988 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.602&r2=1.603 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.955&r2=1.956 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1192&r2=1.1193 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.363&r2=1.364 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/lex.c.diff?cvsroot=gcc&r1=1.325&r2=1.326 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.43&r2=1.44 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.h.diff?cvsroot=gcc&r1=1.18&r2=1.19 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ptree.c.diff?cvsroot=gcc&r1=1.38&r2=1.39 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.287&r2=1.288 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.530&r2=1.531 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3583&r2=1.3584 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/anon-struct4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/union1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/koenig1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/used-before-declaration.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/do1.C.diff?cvsroot=gcc&r1=1.3&r2=1.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/overload/koenig1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/crash13.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/instantiate3.C.diff?cvsroot=gcc&r1=1.2&r2=1.3
Fixed in GCC 3.4 and GCC 3.5.
Subject: Bug 14401 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: gdr@gcc.gnu.org 2004-03-13 02:31:37 Modified files: gcc/cp : ChangeLog class.c init.c Added files: gcc/testsuite/g++.dg/ext: anon-struct4.C gcc/testsuite/g++.dg/init: ctor3.C union1.C Log message: Backport: 2004-03-08 Mark Mitchell <mark@codesourcery.com> PR c++/14401 * class.c (check_field_decls): Complain about non-static data members of reference type in unions. Propagate CLASSTYPE_REF_FIELDS_NEED_INIT and CLASSTYPE_READONLY_FIELDS_NEED_INIT from the types of non-static data members. * init.c (perform_member_init): Complain about members with const type that are not explicitly initialized. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.261&r2=1.3076.2.262 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.499.2.27&r2=1.499.2.28 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.299.2.15&r2=1.299.2.16 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/anon-struct4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.2.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ctor3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.2.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/union1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.2.2.1
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01091.html