decl.c (grokfndecl): Set DECL_CONTEXT to namespace if appropriate.
authorJason Merrill <jason@yorick.cygnus.com>
Sat, 17 Oct 1998 23:01:39 +0000 (23:01 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 17 Oct 1998 23:01:39 +0000 (19:01 -0400)
* decl.c (grokfndecl): Set DECL_CONTEXT to namespace if appropriate.
(grokvardecl): Likewise.

From-SVN: r23157

gcc/cp/ChangeLog
gcc/cp/decl.c

index 5dabdf8f824a2a6984390dde51fa88da3ec9a905..c5bfc5366d25edaebffa0e8d4a507f472ad8ecd6 100644 (file)
@@ -1,3 +1,8 @@
+1998-10-17  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * decl.c (grokfndecl): Set DECL_CONTEXT to namespace if appropriate.
+       (grokvardecl): Likewise.
+
 Sat Oct 17 23:27:20 1998  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * class.c (make_method_vec): Cast 1st argument of `bzero' to (PTR).
index 42cd6ba8beaec7f30cae94f139f9e97debdb5943..40a04e40a4037a0c9fc8f38f26a9424c534780d7 100644 (file)
@@ -8042,9 +8042,11 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
   if (TYPE_VOLATILE (type))
     TREE_THIS_VOLATILE (decl) = 1;
 
-  /* This decl is not from the current namespace. */
+  /* If this decl has namespace scope, set that up.  */
   if (in_namespace)
     set_decl_namespace (decl, in_namespace);
+  else if (publicp && ! ctype)
+    DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
 
   /* `main' and builtins have implicit 'C' linkage.  */
   if ((MAIN_NAME_P (declarator)
@@ -8053,11 +8055,9 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
           && IDENTIFIER_POINTER (declarator)[1] == '_'
           && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
       && current_lang_name == lang_name_cplusplus
-      /* context == 0 could mean global scope or not set yet; either is fine
-        for us here, as we check current_namespace.  */
-      && DECL_CONTEXT (decl) == NULL_TREE
       && ctype == NULL_TREE
-      && current_namespace == global_namespace)
+      /* NULL_TREE means global namespace.  */
+      && DECL_CONTEXT (decl) == NULL_TREE)
     DECL_LANGUAGE (decl) = lang_c;
 
   /* Should probably propagate const out from type to decl I bet (mrs).  */
@@ -8305,12 +8305,21 @@ grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace)
     }
   else
     {
-      tree context = in_namespace ? in_namespace : current_namespace;
+      tree context;
+
+      if (in_namespace)
+       context = in_namespace;
+      else if (namespace_bindings_p () || RIDBIT_SETP (RID_EXTERN, specbits))
+       context = current_namespace;
+
       decl = build_decl (VAR_DECL, declarator, complete_type (type));
-      if (declarator && context != global_namespace && namespace_bindings_p ()
-         && current_lang_name != lang_name_c)
-       DECL_ASSEMBLER_NAME (decl) =  build_static_name (context,
-                                                        declarator);
+
+      if (context)
+       set_decl_namespace (decl, context);
+
+      context = DECL_CONTEXT (decl);
+      if (declarator && context && current_lang_name != lang_name_c)
+       DECL_ASSEMBLER_NAME (decl) = build_static_name (context, declarator);
     }
 
   if (in_namespace)