re PR c++/47956 ([C++0x] gcc accepts static data member declaration with initializer...
authorJason Merrill <jason@redhat.com>
Fri, 27 May 2011 04:01:46 +0000 (00:01 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 27 May 2011 04:01:46 +0000 (00:01 -0400)
PR c++/47956
* decl.c (check_static_variable_definition): Now static.
(cp_finish_decl): Call it here.
(grokdeclarator): Not here.
* pt.c (instantiate_class_template_1): Or here.
* cp-tree.h: Don't declare it.

From-SVN: r174317

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto7.C
gcc/testsuite/g++.dg/template/crash50.C
gcc/testsuite/g++.dg/template/static9.C
gcc/testsuite/g++.old-deja/g++.ext/memconst.C

index 605289fa68fb628b916bcca4804f1f5b855ac28b..577273d3706ae1aaad5a62f33785d8de3aa00d4a 100644 (file)
@@ -1,3 +1,12 @@
+2011-05-26  Jason Merrill  <jason@redhat.com>
+
+       PR c++/47956
+       * decl.c (check_static_variable_definition): Now static.
+       (cp_finish_decl): Call it here.
+       (grokdeclarator): Not here.
+       * pt.c (instantiate_class_template_1): Or here.
+       * cp-tree.h: Don't declare it.
+
 2011-05-26  Janis Johnson  <janis187@us.ibm.com>
            Nathan Froyd  <froydnj@codesourcery.com>
 
index ada01fbd129ceed3112095af809c79497e86e112..a01253e7f4863bc2c0dd435f30971e5946ddfd08 100644 (file)
@@ -4895,7 +4895,6 @@ extern void finish_stmt                           (void);
 extern tree static_fn_type                     (tree);
 extern void revert_static_member_fn            (tree);
 extern void fixup_anonymous_aggr               (tree);
-extern int check_static_variable_definition    (tree, tree);
 extern tree compute_array_index_type           (tree, tree, tsubst_flags_t);
 extern tree check_default_argument             (tree, tree);
 typedef int (*walk_namespaces_fn)              (tree, void *);
index a956dbb266b39d9c5040e6828f92301ed4b3e80f..a5248800b5a05905631e90767a81f59f90b82690 100644 (file)
@@ -74,6 +74,7 @@ static void push_local_name (tree);
 static tree grok_reference_init (tree, tree, tree, tree *);
 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
                         int, int, tree);
+static int check_static_variable_definition (tree, tree);
 static void record_unknown_type (tree, const char *);
 static tree builtin_function_1 (tree, tree, bool);
 static tree build_library_fn_1 (tree, enum tree_code, tree);
@@ -5909,6 +5910,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
   if (current_class_type
       && CP_DECL_CONTEXT (decl) == current_class_type
       && TYPE_BEING_DEFINED (current_class_type)
+      && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type)
       && (DECL_INITIAL (decl) || init))
     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
 
@@ -5939,6 +5941,11 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
   if (!ensure_literal_type_for_constexpr_object (decl))
     DECL_DECLARED_CONSTEXPR_P (decl) = 0;
 
+  if (TREE_CODE (decl) == VAR_DECL
+      && DECL_CLASS_SCOPE_P (decl)
+      && DECL_INITIALIZED_IN_CLASS_P (decl))
+    check_static_variable_definition (decl, type);
+
   if (init && TREE_CODE (decl) == FUNCTION_DECL)
     {
       tree clone;
@@ -7640,9 +7647,12 @@ build_ptrmem_type (tree class_type, tree member_type)
    messages.  Return 1 if the definition is particularly bad, or 0
    otherwise.  */
 
-int
+static int
 check_static_variable_definition (tree decl, tree type)
 {
+  /* Can't check yet if we don't know the type.  */
+  if (dependent_type_p (type))
+    return 0;
   /* If DECL is declared constexpr, we'll do the appropriate checks
      in check_initializer.  */
   if (DECL_P (decl) && DECL_DECLARED_CONSTEXPR_P (decl))
@@ -10025,21 +10035,6 @@ grokdeclarator (const cp_declarator *declarator,
                        staticp = 1;
                      }
                  }
-
-               if (uses_template_parms (type))
-                 /* We'll check at instantiation time.  */
-                 ;
-               else if (constexpr_p)
-                 /* constexpr has the same requirements.  */
-                 ;
-               else if (check_static_variable_definition (unqualified_id,
-                                                          type))
-                 /* If we just return the declaration, crashes
-                    will sometimes occur.  We therefore return
-                    void_type_node, as if this was a friend
-                    declaration, to cause callers to completely
-                    ignore this declaration.  */
-                 return error_mark_node;
              }
 
            if (staticp)
index ab48c8f7f9287f98eb61b03162c404b2b3773389..3b26700244d615ff63f81579213e7abbe0264628 100644 (file)
@@ -8414,8 +8414,6 @@ instantiate_class_template_1 (tree type)
                         /*init_const_expr_p=*/false,
                         /*asmspec_tree=*/NULL_TREE,
                         /*flags=*/0);
-                     if (DECL_INITIALIZED_IN_CLASS_P (r))
-                       check_static_variable_definition (r, TREE_TYPE (r));
                    }
                  else if (TREE_CODE (r) == FIELD_DECL)
                    {
index e0f1e59cd117bc3f120b02a427bb2aadccbfbcaf..8703117b5fee1904569ae4145ae7b65fdf73d76c 100644 (file)
@@ -1,3 +1,10 @@
+2011-05-26  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/auto7.C: Update.
+       * g++.dg/template/crash50.C: Adjust.
+       * g++.dg/template/static9.C: Adjust.
+       * g++.old-deja/g++.ext/memconst.C: Adjust.
+
 2011-05-26  Janis Johnson  <janisjo@codesourcery.com>
 
        * gcc.dg/march.c: Ignore a note for some targets.
index 9ef5a80eb1de643ae3c9eedb485ae35417bbda82..e7ab7236d059d36aa0577067173e83a0cd244759 100644 (file)
@@ -7,7 +7,7 @@ auto j;                 // { dg-error "has no initializer" }
 
 template<int> struct A
 {
-  static auto k = 7;
+  static auto k = 7;   // { dg-error "non-const" }
   static auto l;       // { dg-error "has no initializer" }
   auto m;              // { dg-error "has no initializer" }
 };
index 0060561282f135be95da49901f0a28f732c138f7..286685ac838b7386d08d5ac463d912c140e634cf 100644 (file)
@@ -3,5 +3,5 @@
 
 struct A
 {
-  template<int> void* foo(; // { dg-error "primary-expression|initialization|static" }
+  template<int> void* foo(; // { dg-error "primary-expression|initialization|static|template" }
 };
index 8845647601b4b972f3d1824b9f1eab9de5c970b6..ab70101a19c42a20c374d92393af8050443620e7 100644 (file)
@@ -3,7 +3,6 @@
 template<typename T> struct A
 {
   static const T i = 0; // { dg-error "declared void" "void" }
-                       // { dg-error "invalid|non-literal" "invalid" { target *-*-* } 5 }
 };
 
 A<void> a; // { dg-message "instantiated" }
index 7dd2df736f19305d104854b26098de485670a228..d9347635c2a669263f7629f074b2d1e3e2a3992f 100644 (file)
@@ -21,5 +21,5 @@ public:
 void
 foo::bar ()
 {
-    qwerty QWERTY ((unsigned short*)dummy_key); // { dg-error "" } 
+    qwerty QWERTY ((unsigned short*)dummy_key);
 }