* decl2.c (finish_static_data_member_decl): Complain about a local
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Feb 2002 15:50:01 +0000 (15:50 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Feb 2002 15:50:01 +0000 (15:50 +0000)
        class with a static data member.

        PR c++/4286
        * search.c (lookup_field_1): Don't xref a static data member
        just because we looked it up.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49395 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/search.c
gcc/testsuite/g++.dg/template/local1.C [new file with mode: 0644]

index 91d3dc6..a3aa99e 100644 (file)
@@ -1,3 +1,19 @@
+2002-02-01  Jason Merrill  <jason@redhat.com>
+
+       PR c++/4872
+       * decl.c (finish_function): Warn about a non-void function with 
+       no return statement.
+
+       * error.c (dump_scope): Don't add TFF_DECL_SPECIFIERS.
+       (dump_function_decl): Always dump parms.
+
+       * decl2.c (finish_static_data_member_decl): Complain about a local
+       class with a static data member.
+
+       PR c++/4286
+       * search.c (lookup_field_1): Don't xref a static data member
+       just because we looked it up.
+
 2002-01-31  Jason Merrill  <jason@redhat.com>
 
        * Make-lang.in (parse.c): Handle .output file.
index 70fcf45..9b1c355 100644 (file)
@@ -1420,6 +1420,10 @@ finish_static_data_member_decl (decl, init, asmspec_tree, flags)
       VARRAY_PUSH_TREE (pending_statics, decl);
     }
 
+  if (LOCAL_CLASS_P (current_class_type))
+    pedwarn ("local class `%#T' shall not have static data member `%#D'",
+            current_class_type, decl);
+
   /* Static consts need not be initialized in the class definition.  */
   if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
     {
index 22d5332..10ebc73 100644 (file)
@@ -523,13 +523,7 @@ lookup_field_1 (type, name)
           from TYPE_FIELDS anyhow; see handle_using_decl.  */
        ;
       else if (DECL_NAME (field) == name)
-       {
-         if (TREE_CODE(field) == VAR_DECL 
-             && (TREE_STATIC (field) || DECL_EXTERNAL (field)))
-           GNU_xref_ref(current_function_decl,
-                        IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field)));
-         return field;
-       }
+       return field;
       field = TREE_CHAIN (field);
     }
   /* Not found.  */
diff --git a/gcc/testsuite/g++.dg/template/local1.C b/gcc/testsuite/g++.dg/template/local1.C
new file mode 100644 (file)
index 0000000..85b0056
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/4286: We were crashing when trying to set up the class bindings in
+// g(), because xref wanted the mangled name, which breaks inside a template.
+
+// Of course, the offending code is actually ill-formed anyway, so check
+// for the error.
+
+struct A
+{
+  template<class T> void f();
+};
+
+template<class T> void A::f()
+{
+  struct B
+  {
+    void g() {}
+    static int x;              // { dg-error "static" "" }
+  };
+}
+
+int main ()
+{
+  A a;
+  a.f<int> ();
+}