This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ patch] for C++/52369
- From: Fabien Chêne <fabien dot chene at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 23 Mar 2014 20:47:16 +0100
- Subject: Re: [C++ patch] for C++/52369
- Authentication-results: sourceware.org; auth=none
- References: <CAFH4-diup6eH5j3MhZcknAAia+6ZSyzwD5D94WV0NMa+otgjFg at mail dot gmail dot com> <CAFH4-dgpyn56MQN-7bXM9teA9tBWSFYbcsjiAG5TT53YU04XjA at mail dot gmail dot com> <530F8315 dot 5010703 at redhat dot com> <CAFH4-dgj=JNDHuy2gaW0G9VcdwgrLMiGQg1JHuJHdB-Fcb2SQQ at mail dot gmail dot com> <5310FF29 dot 6060102 at redhat dot com> <CAFH4-diMgdJBTGV=fRZaESLhR4aGR_i8zyL1j99-sKD5eJRFQg at mail dot gmail dot com> <CAFH4-djUxkPYoThf-Gxhf-ZxFkPdEphHYprcDDhBtvHt3PC-6w at mail dot gmail dot com> <5313D7EB dot 8080801 at redhat dot com>
Hi, sorry for the delay,
2014-03-03 2:16 GMT+01:00 Jason Merrill <jason@redhat.com>:
[...]
> Yes, in C++11 the point of use is the source location of the constructor,
> which is going to be different from where the constructor is called. I just
> meant use the same wording.
There we are, locating a point of use that is synthesized. Well, I
guess the best we can do is to point to the class name and mention
said synthesized special function (default constructor here), which is
actually done.
>> I am inclined to think that if we reached one the two functions
>> mentioned, an error had already been raised and we are trying to
>> explain why. Thus, it seems to me that only notes should be emitted.
>> Here we are actually explaining why the default constructor is
>> deleted, which is a kind of subnote.
>
> I can see that argument, but it's deleted because if it were defined, that
> definition would be ill-formed, and we're giving the errors that we would
> see in that case.
Being aware of the logic, it undoubtly makes sense.
Tested x86_64 linux without regressions, OK to commit ?
2014-03-21 Fabien Chene <fabien@gcc.gnu.org>
PR c++/52369
* cp/method.c (walk_field_subobs): improve the diagnostic
locations for both REFERENCE_TYPEs and non-static const members.
* cp/init.c (diagnose_uninitialized_cst_or_ref_member): use %q#D
instead of %qD to be consistent with the c++11 diagnostic.
2014-03-21 Fabien Chene <fabien@gcc.gnu.org>
PR c++/52369
* g++.dg/init/const10.C: New.
* g++.dg/init/const11.C: New.
* g++.dg/init/pr25811.C: Adjust.
* g++.dg/init/pr29043.C: Likewise.
* g++.dg/init/pr43719.C: Likewise.
* g++.dg/init/pr44086.C: Likewise.
* g++.dg/init/ctor4.C: Likewise.
* g++.dg/init/ctor8.C: Likewise.
* g++.dg/init/uninitialized1.C: Likewise.
--
Fabien
Index: gcc/testsuite/g++.dg/init/pr25811.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr25811.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/pr25811.C (copie de travail)
@@ -1,51 +1,60 @@
// PR c++/25811
// { dg-do compile }
-struct A1 // { dg-error "uninitialized" "" { target c++11 } }
+struct A1 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 4 }
{
- int const j; // { dg-message "should be initialized" "" { target c++98 } }
+ int const j; // { dg-message "should be initialized" }
};
-struct A2 // { dg-error "uninitialized" "" { target c++11 } }
+struct A2 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 10 }
{
- int const volatile i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const volatile i; // { dg-message "should be initialized" }
};
-struct A3 // { dg-error "uninitialized" "" { target c++11 } }
+struct A3 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 16 }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
-struct A4 // { dg-error "uninitialized" "" { target c++11 } }
+struct A4 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 22 }
{
- int const& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int const& ref; // { dg-message "should be initialized" }
};
-struct A5 // { dg-error "uninitialized" "" { target c++11 } }
+struct A5 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 28 }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
+ int const i; // { dg-message "should be initialized" }
};
-template <class T> struct S1 // { dg-error "uninitialized" "" { target c++11 } }
+template <class T> struct S1 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 35 }
{
- T const i; // { dg-message "should be initialized" "" { target c++98 } }
+ T const i; // { dg-message "should be initialized" }
};
-template <class T> struct S2 // { dg-error "uninitialized" "" { target c++11 } }
+template <class T> struct S2 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 41 }
{
- T const volatile i; // { dg-message "should be initialized" "" { target c++98 } }
+ T const volatile i; // { dg-message "should be initialized" }
};
-template <class T> struct S3 // { dg-error "uninitialized" "" { target c++11 } }
+template <class T> struct S3 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 47 }
{
- T& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ T& ref; // { dg-message "should be initialized" }
};
-template <class T> struct S4 // { dg-error "uninitialized" "" { target c++11 } }
+template <class T> struct S4 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 53 }
{
- T const i; // { dg-message "should be initialized" "" { target c++98 } }
- T& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ T const i; // { dg-message "should be initialized" }
+ T& ref; // { dg-message "should be initialized" }
};
struct X
@@ -55,44 +64,50 @@ struct X
int const& r;
};
-struct Y11 // { dg-error "uninitialized" "" { target c++11 } }
+struct Y11 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 67 }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
-struct Y1 // { dg-error "deleted" "" { target c++11 } }
+struct Y1 // { dg-error "deleted" "" { target c++11 } }
{
Y11 a[1];
};
-struct Y22 // { dg-error "uninitialized" "" { target c++11 } }
+struct Y22 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 78 }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
-struct Y2 // { dg-error "deleted" "" { target c++11 } }
+struct Y2 // { dg-error "deleted" "" { target c++11 } }
{
Y22 a[1];
};
-struct Z1 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z1 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 89 }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
-struct Z2 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z2 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 95 }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
-struct Z3 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z3 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 101 }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
-struct Z4 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z4 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 107 }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
struct Z5
@@ -100,7 +115,7 @@ struct Z5
int i;
};
-struct Z // { dg-error "deleted" "" { target c++11 } }
+struct Z // { dg-error "deleted" "" { target c++11 } }
{
Z1 z1;
Z2 z2;
@@ -109,9 +124,10 @@ struct Z // { dg-error "deleted" "" { t
Z5 z5;
};
-union U // { dg-error "uninitialized" "" { target c++11 } }
+union U // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 127 }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
void f1 ()
Index: gcc/testsuite/g++.dg/init/ctor8.C
===================================================================
--- gcc/testsuite/g++.dg/init/ctor8.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/ctor8.C (copie de travail)
@@ -1,6 +1,6 @@
// PR c++/29039
-typedef struct S { // { dg-error "reference" "" { target c++11 } }
+typedef struct S { // { dg-error "reference" "" { target c++11 } }
int &r;
}; // { dg-warning "'typedef' was ignored" }
Index: gcc/testsuite/g++.dg/init/pr29043.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr29043.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/pr29043.C (copie de travail)
@@ -1,9 +1,10 @@
// PR c++/29043
// { dg-do compile }
-struct S // { dg-error "uninitialized" "" { target c++11 } }
+struct S // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 4 }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
class C
@@ -13,9 +14,10 @@ public:
S s;
};
-struct S2 // { dg-error "uninitialized" "" { target c++11 } }
+struct S2 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 17 }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
class C2
@@ -33,9 +35,10 @@ class C3
};
};
-struct S4 // { dg-error "uninitialized" "" { target c++11 } }
+struct S4 // { dg-message "implicitly deleted" "" { target c++11 } }
+ // { dg-error "uninitialized" "" { target c++11 } 38 }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
struct C4
@@ -46,7 +49,7 @@ struct C4
struct C5
{
- C5() {} // { dg-message "uninitialized" }
+ C5() {} // { dg-error "uninitialized" }
int const iit[ 1 ];
};
Index: gcc/testsuite/g++.dg/init/const10.C
===================================================================
--- gcc/testsuite/g++.dg/init/const10.C (révision 0)
+++ gcc/testsuite/g++.dg/init/const10.C (révision 0)
@@ -0,0 +1,33 @@
+// PR C++/52369
+// { dg-do compile { target c++11 } }
+
+class B // { dg-message "implicitly deleted" }
+ // { dg-error "uninitialized" "" { target c++11 } 4 }
+{
+ int const v_; // { dg-message "should be initialized" }
+};
+
+struct D : B {}; // { dg-error "deleted" }
+
+class A // { dg-message "implicitly deleted" }
+ // { dg-error "uninitialized" "" { target c++11 } 12 }
+{
+ int& ref; // { dg-message "should be initialized" }
+};
+
+struct C : A {}; // { dg-error "deleted" }
+
+void f()
+{
+ D d; // { dg-error "use of deleted" }
+ new D; // { dg-error "use of deleted" }
+ D(); // { dg-error "use of deleted" }
+ new D(); // { dg-error "use of deleted" }
+
+ C c; // { dg-error "use of deleted" }
+ new C; // { dg-error "use of deleted" }
+ C(); // { dg-error "use of deleted" }
+ new C(); // { dg-error "use of deleted" }
+}
+
+
Index: gcc/testsuite/g++.dg/init/pr44086.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr44086.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/pr44086.C (copie de travail)
@@ -1,9 +1,9 @@
// PR c++/44086
// { dg-do compile }
-struct A // { dg-error "uninitialized" "" { target c++11 } }
+struct A // { dg-error "uninitialized" "" { target c++11 } }
{
- int const i : 2; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i : 2; // { dg-message "should be initialized" }
};
void f()
Index: gcc/testsuite/g++.dg/init/const11.C
===================================================================
--- gcc/testsuite/g++.dg/init/const11.C (révision 0)
+++ gcc/testsuite/g++.dg/init/const11.C (révision 0)
@@ -0,0 +1,29 @@
+// PR C++/52369
+// { dg-do compile { target c++98 } }
+
+class B
+{
+ int const v_; // { dg-message "should be initialized" }
+};
+
+struct D : B {};
+
+class A
+{
+ int& ref; // { dg-message "should be initialized" }
+};
+
+struct C : A {};
+
+void f()
+{
+ D d; // { dg-error "uninitialized" }
+ new D; // { dg-error "uninitialized" }
+ D();
+ new D();
+
+ C c; // { dg-error "uninitialized" }
+ new C; // { dg-error "uninitialized" }
+ C(); // { dg-error "value-initialization" }
+ new C(); // { dg-error "value-initialization" }
+}
Index: gcc/testsuite/g++.dg/init/ctor4.C
===================================================================
--- gcc/testsuite/g++.dg/init/ctor4.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/ctor4.C (copie de travail)
@@ -6,7 +6,7 @@ public:
foo();
};
-class bar: public foo { // { dg-error "reference|bar::bar" }
+class bar: public foo { // { dg-error "uninitialized|bar::bar" }
private:
int &a;
};
Index: gcc/testsuite/g++.dg/init/uninitialized1.C
===================================================================
--- gcc/testsuite/g++.dg/init/uninitialized1.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/uninitialized1.C (copie de travail)
@@ -1,8 +1,8 @@
// PR c++/58126
-struct A { // { dg-error "uninitialized" "" { target c++11 } }
- const int value1;
- int& value2;
+struct A { // { dg-error "uninitialized" "" { target c++11 } }
+ const int value1; // { dg-message "should be initialized" }
+ int& value2; // { dg-message "should be initialized" }
};
struct B : A { }; // { dg-error "deleted" "" { target c++11 } }
Index: gcc/testsuite/g++.dg/init/pr43719.C
===================================================================
--- gcc/testsuite/g++.dg/init/pr43719.C (révision 207406)
+++ gcc/testsuite/g++.dg/init/pr43719.C (copie de travail)
@@ -1,51 +1,51 @@
// PR c++/43719
// { dg-do compile }
-struct A1 // { dg-error "uninitialized" "" { target c++11 } }
+struct A1 // { dg-error "uninitialized" "" { target c++11 } }
{
- int const j; // { dg-message "should be initialized" "" { target c++98 } }
+ int const j; // { dg-message "should be initialized" }
};
-struct A2 // { dg-error "uninitialized" "" { target c++11 } }
+struct A2 // { dg-error "uninitialized" "" { target c++11 } }
{
- int const volatile i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const volatile i; // { dg-message "should be initialized" }
};
-struct A3 // { dg-error "uninitialized" "" { target c++11 } }
+struct A3 // { dg-error "uninitialized" "" { target c++11 } }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
-struct A4 // { dg-error "uninitialized" "" { target c++11 } }
+struct A4 // { dg-error "uninitialized" "" { target c++11 } }
{
- int const& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int const& ref; // { dg-message "should be initialized" }
};
-struct A5 // { dg-error "uninitialized" "" { target c++11 } }
+struct A5 // { dg-error "uninitialized" "" { target c++11 } }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
+ int const i; // { dg-message "should be initialized" }
};
template <class T> struct S1 // { dg-error "uninitialized" "" { target c++11 } }
{
- T const i; // { dg-message "should be initialized" "" { target c++98 } }
+ T const i; // { dg-message "should be initialized" }
};
template <class T> struct S2 // { dg-error "uninitialized" "" { target c++11 } }
{
- T const volatile i; // { dg-message "should be initialized" "" { target c++98 } }
+ T const volatile i; // { dg-message "should be initialized" }
};
template <class T> struct S3 // { dg-error "uninitialized" "" { target c++11 } }
{
- T& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ T& ref; // { dg-message "should be initialized" }
};
template <class T> struct S4 // { dg-error "uninitialized" "" { target c++11 } }
{
- T const i; // { dg-message "should be initialized" "" { target c++98 } }
- T& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ T const i; // { dg-message "should be initialized" }
+ T& ref; // { dg-message "should be initialized" }
};
struct X
@@ -55,9 +55,9 @@ struct X
int const& r;
};
-struct Y11 // { dg-error "uninitialized" "" { target c++11 } }
+struct Y11 // { dg-error "uninitialized" "" { target c++11 } }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
struct Y1 // { dg-error "deleted" "" { target c++11 } }
@@ -65,9 +65,9 @@ struct Y1 // { dg-error "deleted" ""
Y11 a[1];
};
-struct Y22 // { dg-error "uninitialized" "" { target c++11 } }
+struct Y22 // { dg-error "uninitialized" "" { target c++11 } }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
struct Y2 // { dg-error "deleted" "" { target c++11 } }
@@ -75,24 +75,24 @@ struct Y2 // { dg-error "deleted"
Y22 a[1];
};
-struct Z1 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z1 // { dg-error "uninitialized" "" { target c++11 } }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
-struct Z2 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z2 // { dg-error "uninitialized" "" { target c++11 } }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
-struct Z3 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z3 // { dg-error "uninitialized" "" { target c++11 } }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
-struct Z4 // { dg-error "uninitialized" "" { target c++11 } }
+struct Z4 // { dg-error "uninitialized" "" { target c++11 } }
{
- int& ref; // { dg-message "should be initialized" "" { target c++98 } }
+ int& ref; // { dg-message "should be initialized" }
};
struct Z5
@@ -109,9 +109,9 @@ struct Z // { dg-error "deleted" "" { t
Z5 z5;
};
-union U // { dg-error "uninitialized" "" { target c++11 } }
+union U // { dg-error "uninitialized" "" { target c++11 } }
{
- int const i; // { dg-message "should be initialized" "" { target c++98 } }
+ int const i; // { dg-message "should be initialized" }
};
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (révision 207406)
+++ gcc/cp/init.c (copie de travail)
@@ -2148,7 +2148,7 @@ diagnose_uninitialized_cst_or_ref_member
"of %q#T", DECL_CONTEXT (field), origin);
}
inform (DECL_SOURCE_LOCATION (field),
- "%qD should be initialized", field);
+ "%q#D should be initialized", field);
}
}
@@ -2176,7 +2176,7 @@ diagnose_uninitialized_cst_or_ref_member
"of %q#T", DECL_CONTEXT (field), origin);
}
inform (DECL_SOURCE_LOCATION (field),
- "%qD should be initialized", field);
+ "%q#D should be initialized", field);
}
}
Index: gcc/cp/method.c
===================================================================
--- gcc/cp/method.c (révision 207406)
+++ gcc/cp/method.c (copie de travail)
@@ -1091,15 +1091,23 @@ walk_field_subobs (tree fields, tree fnn
&& default_init_uninitialized_part (mem_type))
{
if (diag)
- error ("uninitialized non-static const member %q#D",
- field);
+ {
+ error ("uninitialized const member in %q#T",
+ current_class_type);
+ inform (DECL_SOURCE_LOCATION (field),
+ "%q#D should be initialized", field);
+ }
bad = true;
}
else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
{
if (diag)
- error ("uninitialized non-static reference member %q#D",
- field);
+ {
+ error ("uninitialized reference member in %q#T",
+ current_class_type);
+ inform (DECL_SOURCE_LOCATION (field),
+ "%q#D should be initialized", field);
+ }
bad = true;
}