diff mbox

[C++] for C++/52369

Message ID CAFH4-div6q7MB9-BxppPZrqcCe0vXY9pL=8hp_c1vPCnHF9BLA@mail.gmail.com
State New
Headers show

Commit Message

Fabien Chêne March 31, 2014, 8:27 p.m. UTC
2014-03-28 17:59 GMT+01:00 Jason Merrill <jason@redhat.com>:
> 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.

I missed a third case just a few lines above, that I adjusted in the
same manner, by checking the return value of permerror.
Tested x86_64 linux, OK to commit ?

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

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

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

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

Comments

Jason Merrill March 31, 2014, 9:48 p.m. UTC | #1
On 03/31/2014 04:27 PM, Fabien Chêne wrote:
>      * cp/init.c (perform_member_init): Homogenize uninitialized
>      diagnostics.

OK.

> 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 ?

Yes.

Jason
diff mbox

Patch

Index: gcc/testsuite/g++.dg/init/ctor4.C
===================================================================
--- gcc/testsuite/g++.dg/init/ctor4.C	(révision 208923)
+++ 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/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/cpp0x/defaulted2.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted2.C	(révision 208923)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted2.C	(copie de travail)
@@ -35,7 +35,7 @@  struct D: public C
 
 struct E
 {
-  const B b;
+  const B b;			// { dg-message "should be initialized" }
   E() { }			// { dg-error "uninitialized" }
 };
 
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(révision 208923)
+++ gcc/cp/init.c	(copie de travail)
@@ -694,11 +694,14 @@  perform_member_init (tree member, tree i
 	  if (CP_TYPE_CONST_P (type)
 	      && init == NULL_TREE
 	      && default_init_uninitialized_part (type))
-	    /* TYPE_NEEDS_CONSTRUCTING can be set just because we have a
-	       vtable; still give this diagnostic.  */
-	    permerror (DECL_SOURCE_LOCATION (current_function_decl),
-		       "uninitialized member %qD with %<const%> type %qT",
-		       member, type);
+	    {
+	      /* TYPE_NEEDS_CONSTRUCTING can be set just because we have a
+		 vtable; still give this diagnostic.  */
+	      if (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 );
+	    }
 	  finish_expr_stmt (build_aggr_init (decl, init, flags,
 					     tf_warning_or_error));
 	}
@@ -710,13 +713,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);
+	    {
+	      if (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);
+	    {
+	      if (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);