decl.c (grokdeclarator): Set context of namespace scope TYPE_DECLS.
authorNathan Sidwell <nathan@codesourcery.com>
Wed, 25 Apr 2001 08:31:19 +0000 (08:31 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 25 Apr 2001 08:31:19 +0000 (08:31 +0000)
cp:
* decl.c (grokdeclarator): Set context of namespace scope
TYPE_DECLS.
testsuite:
* g++.old-deja/g++.ns/type2.C: New test.

From-SVN: r41533

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.ns/type2.C [new file with mode: 0644]

index 618ba0d7b413d238127ffa271f4777cb849d355b..4ea7d43e835d929781f8a09f0d141af52ecf1635 100644 (file)
@@ -1,3 +1,8 @@
+2001-04-25  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * decl.c (grokdeclarator): Set context of namespace scope
+       TYPE_DECLS.
+
 2001-04-24  Zack Weinberg  <zackw@stanford.edu>
 
        * cp/optimize.c: Include hashtab.h.
index 834e2dcd5da04e1ce14a72f9af645ac0c41d1312..ea37eb45c0d7b7eb82d70cffbfe6c335f538c45f 100644 (file)
@@ -11035,8 +11035,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
          decl = build_lang_decl (TYPE_DECL, declarator, type);
        }
       else
-       decl = build_decl (TYPE_DECL, declarator, type);
-
+       {
+         decl = build_decl (TYPE_DECL, declarator, type);
+         if (!current_function_decl)
+           DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
+       }
+      
       /* If the user declares "typedef struct {...} foo" then the
         struct will have an anonymous name.  Fill that name in now.
         Nothing can refer to it, so nothing needs know about the name
index 39abc4e4905814ef83bf90aaa18dbcab4ca0b726..a0f0f2504d4a939058855814df8a8dad60b125dc 100644 (file)
@@ -1,3 +1,7 @@
+2001-04-25  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.ns/type2.C: New test.
+
 2001-04-24  Zack Weinberg  <zackw@stanford.edu>
 
        * g++.old-deja/g++.other/perf1.C: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.ns/type2.C b/gcc/testsuite/g++.old-deja/g++.ns/type2.C
new file mode 100644 (file)
index 0000000..d8407b1
--- /dev/null
@@ -0,0 +1,19 @@
+// Build don't link:
+// 
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 11 April 2001 <nathan@codesourcery.com>
+// Origin:stephen.webb@cybersafe.com 
+
+// Bug 2125. TYPE_DECLS never had their DECL_CONTEXT set, which
+// confused forward references to classes.
+
+typedef void T;
+namespace A {
+  class C;
+  typedef class C C;
+  typedef int T;
+  class C
+  {
+    T i;               // got bogus error, found wrong T
+  };
+}