* [C++ Patch/RFC] PR 49132
@ 2014-06-24 21:35 Paolo Carlini
2014-06-24 22:11 ` Paolo Carlini
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2014-06-24 21:35 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 422 bytes --]
Hi,
this remained unresolved for a long time, but, if I understand correctly
Jason' Comment 1, should be rather easy, just do not complain for
uninitialized const members in aggregates, recursively too (per struct B
in the testcases). Does the below makes sense, then?!? It passes
testing, anyway. I'm also taking the occasion to guard the warnings with
complain & tf_warning.
Thanks,
Paolo.
/////////////////////
[-- Attachment #2: patch_49132 --]
[-- Type: text/plain, Size: 2492 bytes --]
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 211955)
+++ cp/typeck2.c (working copy)
@@ -1342,28 +1342,15 @@ process_init_constructor_record (tree type, tree i
next = massage_init_elt (TREE_TYPE (field), next, complain);
/* Warn when some struct elements are implicitly initialized. */
- warning (OPT_Wmissing_field_initializers,
- "missing initializer for member %qD", field);
+ if (complain & tf_warning)
+ warning (OPT_Wmissing_field_initializers,
+ "missing initializer for member %qD", field);
}
else
{
- if (TREE_READONLY (field))
+ if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
{
if (complain & tf_error)
- error ("uninitialized const member %qD", field);
- else
- return PICFLAG_ERRONEOUS;
- }
- else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
- {
- if (complain & tf_error)
- error ("member %qD with uninitialized const fields", field);
- else
- return PICFLAG_ERRONEOUS;
- }
- else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
- {
- if (complain & tf_error)
error ("member %qD is uninitialized reference", field);
else
return PICFLAG_ERRONEOUS;
@@ -1371,8 +1358,9 @@ process_init_constructor_record (tree type, tree i
/* Warn when some struct elements are implicitly initialized
to zero. */
- warning (OPT_Wmissing_field_initializers,
- "missing initializer for member %qD", field);
+ if (complain & tf_warning)
+ warning (OPT_Wmissing_field_initializers,
+ "missing initializer for member %qD", field);
if (!zero_init_p (TREE_TYPE (field)))
next = build_zero_init (TREE_TYPE (field), /*nelts=*/NULL_TREE,
Index: testsuite/g++.dg/cpp0x/aggr1.C
===================================================================
--- testsuite/g++.dg/cpp0x/aggr1.C (revision 0)
+++ testsuite/g++.dg/cpp0x/aggr1.C (working copy)
@@ -0,0 +1,16 @@
+// PR c++/49132
+// { dg-do compile { target c++11 } }
+
+struct A {
+ const int m;
+};
+
+A a1 = {};
+A a2{};
+
+struct B {
+ A a;
+};
+
+B b1 = {};
+B b2{};
Index: testsuite/g++.dg/init/aggr11.C
===================================================================
--- testsuite/g++.dg/init/aggr11.C (revision 0)
+++ testsuite/g++.dg/init/aggr11.C (working copy)
@@ -0,0 +1,13 @@
+// PR c++/49132
+
+struct A {
+ const int m;
+};
+
+A a1 = {};
+
+struct B {
+ A a;
+};
+
+B b1 = {};
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C++ Patch/RFC] PR 49132
2014-06-24 21:35 [C++ Patch/RFC] PR 49132 Paolo Carlini
@ 2014-06-24 22:11 ` Paolo Carlini
2014-06-25 12:37 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2014-06-24 22:11 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 357 bytes --]
... in order to handle correctly in C++98 mode (*) the case of
references in a member, I think we have to add an explicit check of
CLASSTYPE_REF_FIELDS_NEED_INIT, per the below.
Thanks,
Paolo.
(*) For C++11 my previous patch is fine, the TREE_CODE (TREE_TYPE
(field)) == REFERENCE_TYPE check catches also references in members.
////////////////////
[-- Attachment #2: patch_49132_2 --]
[-- Type: text/plain, Size: 3580 bytes --]
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 211955)
+++ cp/typeck2.c (working copy)
@@ -1342,37 +1342,32 @@ process_init_constructor_record (tree type, tree i
next = massage_init_elt (TREE_TYPE (field), next, complain);
/* Warn when some struct elements are implicitly initialized. */
- warning (OPT_Wmissing_field_initializers,
- "missing initializer for member %qD", field);
+ if (complain & tf_warning)
+ warning (OPT_Wmissing_field_initializers,
+ "missing initializer for member %qD", field);
}
else
{
- if (TREE_READONLY (field))
+ if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
{
if (complain & tf_error)
- error ("uninitialized const member %qD", field);
+ error ("member %qD is uninitialized reference", field);
else
return PICFLAG_ERRONEOUS;
}
- else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
+ else if (CLASSTYPE_REF_FIELDS_NEED_INIT (TREE_TYPE (field)))
{
if (complain & tf_error)
- error ("member %qD with uninitialized const fields", field);
+ error ("member %qD with uninitialized reference fields", field);
else
return PICFLAG_ERRONEOUS;
}
- else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
- {
- if (complain & tf_error)
- error ("member %qD is uninitialized reference", field);
- else
- return PICFLAG_ERRONEOUS;
- }
/* Warn when some struct elements are implicitly initialized
to zero. */
- warning (OPT_Wmissing_field_initializers,
- "missing initializer for member %qD", field);
+ if (complain & tf_warning)
+ warning (OPT_Wmissing_field_initializers,
+ "missing initializer for member %qD", field);
if (!zero_init_p (TREE_TYPE (field)))
next = build_zero_init (TREE_TYPE (field), /*nelts=*/NULL_TREE,
Index: testsuite/g++.dg/cpp0x/aggr1.C
===================================================================
--- testsuite/g++.dg/cpp0x/aggr1.C (revision 0)
+++ testsuite/g++.dg/cpp0x/aggr1.C (working copy)
@@ -0,0 +1,16 @@
+// PR c++/49132
+// { dg-do compile { target c++11 } }
+
+struct A {
+ const int m;
+};
+
+A a1 = {};
+A a2{};
+
+struct B {
+ A a;
+};
+
+B b1 = {};
+B b2{};
Index: testsuite/g++.dg/cpp0x/aggr2.C
===================================================================
--- testsuite/g++.dg/cpp0x/aggr2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/aggr2.C (working copy)
@@ -0,0 +1,16 @@
+// PR c++/49132
+// { dg-do compile { target c++11 } }
+
+struct A {
+ int& m;
+};
+
+A a1 = {}; // { dg-error "uninitialized reference" }
+A a2{}; // { dg-error "uninitialized reference" }
+
+struct B {
+ A a;
+};
+
+B b1 = {}; // { dg-error "uninitialized reference" }
+B b2{}; // { dg-error "uninitialized reference" }
Index: testsuite/g++.dg/init/aggr11.C
===================================================================
--- testsuite/g++.dg/init/aggr11.C (revision 0)
+++ testsuite/g++.dg/init/aggr11.C (working copy)
@@ -0,0 +1,13 @@
+// PR c++/49132
+
+struct A {
+ const int m;
+};
+
+A a1 = {};
+
+struct B {
+ A a;
+};
+
+B b1 = {};
Index: testsuite/g++.dg/init/aggr12.C
===================================================================
--- testsuite/g++.dg/init/aggr12.C (revision 0)
+++ testsuite/g++.dg/init/aggr12.C (working copy)
@@ -0,0 +1,13 @@
+// PR c++/49132
+
+struct A {
+ int& m;
+};
+
+A a1 = {}; // { dg-error "uninitialized reference" }
+
+struct B {
+ A a;
+};
+
+B b1 = {}; // { dg-error "uninitialized reference" }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C++ Patch/RFC] PR 49132
2014-06-24 22:11 ` Paolo Carlini
@ 2014-06-25 12:37 ` Jason Merrill
0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2014-06-25 12:37 UTC (permalink / raw)
To: Paolo Carlini, gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-25 12:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-24 21:35 [C++ Patch/RFC] PR 49132 Paolo Carlini
2014-06-24 22:11 ` Paolo Carlini
2014-06-25 12:37 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).