diff mbox

[C++] for C++/52369

Message ID CAFH4-di3mpWOfpKONhH5z3r3-psD+osNi0s-FAw-X1KqN=aukA@mail.gmail.com
State New
Headers show

Commit Message

Fabien Chêne March 27, 2014, 9:32 p.m. UTC
Hi,

As a followup, the following patch homogeneise some diagnostics that
relate to uninitialized const or reference members.
Tested x86_64 linux in progress, OK to commit for next stage 1 if that
succeeds ? (or trunk otherwise, I dare to mention it).

2014-03-28  Fabien Chêne  <fabien@gcc.gnu.org>

    * cp/init.c (perform_member_init): homogeneize uninitialized
    diagnostics.

2014-03-28  Fabien Chêne  <fabien@gcc.gnu.org>

        * g++.dg/init/ctor4.C: Adjust.
    * g++.dg/init/ctor4-1.C: New.

2014-03-24 18:21 GMT+01:00 Jason Merrill <jason@redhat.com>:
> OK, thanks.
>
> Jason

Comments

Jason Merrill March 28, 2014, 4:59 p.m. UTC | #1
On 03/27/2014 05:32 PM, Fabien Chêne wrote:
> +	      permerror (DECL_SOURCE_LOCATION (current_function_decl),
> +			 "uninitialized reference member in %q#T", type);
> +	      inform (DECL_SOURCE_LOCATION (member),
> +		      "%q#D should be initialized", member);

The inform should only happen if permerror returns true (i.e. without 
-fpermissive -w).  OK with that change.

Jason
Mike Stump March 28, 2014, 7:27 p.m. UTC | #2
Just a nit…

> 2014-03-28  Fabien Chêne  <fabien@gcc.gnu.org>
> 
>    * cp/init.c (perform_member_init): homogeneize uninitialized
>    diagnostics.

Sentences begin with an upper case letter, and spelling…  Homogenize..
Fabien Chêne March 31, 2014, 8:12 p.m. UTC | #3
2014-03-28 20:27 GMT+01:00 Mike Stump <mikestump@comcast.net>:
> Just a nit...
>
>> 2014-03-28  Fabien Chêne  <fabien@gcc.gnu.org>
>>
>>    * cp/init.c (perform_member_init): homogeneize uninitialized
>>    diagnostics.
>
> Sentences begin with an upper case letter, and spelling...  Homogenize..

I will fix that, thanks.
Fabien Chêne March 31, 2014, 8:28 p.m. UTC | #4
2014-03-28 17:59 GMT+01:00 Jason Merrill <jason@redhat.com>:
[...]
> The inform should only happen if permerror returns true (i.e. without
> -fpermissive -w).  OK with that change.

I did a little tour around the permerror uses, and found that in decl.c:

if (permerror (input_location,
                       "default argument given for parameter "
                       "%d of %q#D", i, newdecl))
              permerror (DECL_SOURCE_LOCATION (olddecl),
                     "previous specification in %q#D here",
                     olddecl);

should the second permerror be a note instead ?
diff mbox

Patch

Index: gcc/testsuite/g++.dg/init/ctor4-1.C
===================================================================
--- gcc/testsuite/g++.dg/init/ctor4-1.C	(révision 0)
+++ gcc/testsuite/g++.dg/init/ctor4-1.C	(révision 0)
@@ -0,0 +1,21 @@ 
+// { dg-do compile }
+
+class foo {
+public:
+  foo();
+};
+
+class bar: public foo {	// { dg-error "uninitialized" }
+		   // { dg-message "implicitly deleted" "" { target c++11 } 8 }
+private:
+  int const a; // { dg-message "should be initialized" }
+};
+
+foo::foo() {
+}
+
+int main(int argc, char **argv)
+{
+  bar x; // { dg-error "deleted" "" { target c++11 } }
+	 // { dg-message "synthesized" "" { target { ! c++11 } } 19 }
+}
Index: gcc/testsuite/g++.dg/init/ctor4.C
===================================================================
--- gcc/testsuite/g++.dg/init/ctor4.C	(révision 208853)
+++ gcc/testsuite/g++.dg/init/ctor4.C	(copie de travail)
@@ -6,9 +6,10 @@  public:
   foo();
 };
 
-class bar: public foo {		// { dg-error "reference|bar::bar" }
+class bar: public foo {	// { dg-error "uninitialized" }
+		   // { dg-message "implicitly deleted" "" { target c++11 } 9 }
 private:
-  int &a;
+  int &a; // { dg-message "should be initialized" }
 };
 
 foo::foo() {
@@ -16,5 +17,6 @@  foo::foo() {
 
 int main(int argc, char **argv)
 {
-  bar x; // { dg-message "synthesized|deleted" }
+  bar x; // { dg-error "deleted" "" { target c++11 } }
+         // { dg-message "synthesized" "" { target { ! c++11 } } 20 }
 }
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(révision 208854)
+++ gcc/cp/init.c	(copie de travail)
@@ -710,13 +710,19 @@  perform_member_init (tree member, tree i
 	  tree core_type;
 	  /* member traversal: note it leaves init NULL */
 	  if (TREE_CODE (type) == REFERENCE_TYPE)
-	    permerror (DECL_SOURCE_LOCATION (current_function_decl),
-		       "uninitialized reference member %qD",
-		       member);
+	    {
+	      permerror (DECL_SOURCE_LOCATION (current_function_decl),
+			 "uninitialized reference member in %q#T", type);
+	      inform (DECL_SOURCE_LOCATION (member),
+		      "%q#D should be initialized", member);
+	    }
 	  else if (CP_TYPE_CONST_P (type))
-	    permerror (DECL_SOURCE_LOCATION (current_function_decl),
-		       "uninitialized member %qD with %<const%> type %qT",
-		       member, type);
+	    {
+	      permerror (DECL_SOURCE_LOCATION (current_function_decl),
+			 "uninitialized const member in %q#T", type);
+	      inform (DECL_SOURCE_LOCATION (member),
+		      "%q#D should be initialized", member );
+	    }
 
 	  core_type = strip_array_types (type);