This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ patch] for C++/52369


Hi,

This bug seems already fixed on mainline. I have added two testcases,
but as the C++11 one is not obvious to me, I guess this path does not
qualify as obvious. Incidentally, while writing the C++11 testcase, I
realized that the diagnostic was not emitted at the proper location
and fixed it.

OK for trunk ?

2014-02-06  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.

2014-02-06  Fabien Chene  <fabien@gcc.gnu.org>

        PR c++/52369
        * g++.dg/init/const10.C: New.
        * g++.dg/init/const11.C: New.

-- 
Fabien
Index: gcc/testsuite/g++.dg/init/const10.C
===================================================================
--- gcc/testsuite/g++.dg/init/const10.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/const10.C	(revision 0)
@@ -0,0 +1,31 @@
+// PR C++/52369
+// { dg-do compile { target c++11 } }
+
+class B // { dg-message "implicitly deleted" }
+{
+  int const v_; // { dg-error "uninitialized" }
+};
+
+struct D : B {}; // { dg-error "deleted" }
+
+class A // { dg-message "implicitly deleted" }
+{
+  int& ref; // { dg-error "uninitialized" }
+};
+
+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/const11.C
===================================================================
--- gcc/testsuite/g++.dg/init/const11.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/const11.C	(revision 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/cp/method.c
===================================================================
--- gcc/cp/method.c	(revision 207406)
+++ gcc/cp/method.c	(working copy)
@@ -1091,15 +1091,15 @@ 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_at (DECL_SOURCE_LOCATION (field),
+			  "uninitialized non-static const member %q#D", field);
 	      bad = true;
 	    }
 	  else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
 	    {
 	      if (diag)
-		error ("uninitialized non-static reference member %q#D",
-		       field);
+		error_at (DECL_SOURCE_LOCATION (field),
+			  "uninitialized non-static reference member %q#D", field);
 	      bad = true;
 	    }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]