Patchwork C++ PATCH for c++/51461 (ice-on-invalid with static const data member)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 16, 2011, 10:34 p.m.
Message ID <4EEBC77E.5020609@redhat.com>
Download mbox | patch
Permalink /patch/131929/
State New
Headers show

Comments

Jason Merrill - Dec. 16, 2011, 10:34 p.m.
literal_type_p doesn't like to see incomplete types, so let's check for 
that case first.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 0418652f7ecc0286565abc805d4728872eac32b9
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Dec 16 14:04:01 2011 -0500

    	PR c++/51461
    	* decl.c (check_static_variable_definition): Check COMPLETE_TYPE_P
    	before literal_type_p.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 919e235..fedc52c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5449,7 +5449,7 @@  check_initializer (tree decl, tree init, int flags, VEC(tree,gc) **cleanups)
     }
   else if (!COMPLETE_TYPE_P (type))
     {
-      error ("%qD has incomplete type", decl);
+      error ("%q#D has incomplete type", decl);
       TREE_TYPE (decl) = error_mark_node;
       return NULL_TREE;
     }
@@ -7807,7 +7807,10 @@  check_static_variable_definition (tree decl, tree type)
     return 0;
   else if (cxx_dialect >= cxx0x && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
     {
-      if (literal_type_p (type))
+      if (!COMPLETE_TYPE_P (type))
+	error ("in-class initialization of static data member %q#D of "
+	       "incomplete type", decl);
+      else if (literal_type_p (type))
 	permerror (input_location,
 		   "%<constexpr%> needed for in-class initialization of "
 		   "static data member %q#D of non-integral type", decl);
diff --git a/gcc/testsuite/g++.dg/init/static4.C b/gcc/testsuite/g++.dg/init/static4.C
new file mode 100644
index 0000000..0cdc48b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/static4.C
@@ -0,0 +1,6 @@ 
+// PR c++/51461
+
+struct A
+{
+  static const A a = 0;		// { dg-error "incomplete|non-integral" }
+};