re PR c++/25999 (compiler loses extern "C" for function after #pragma weak)
authorMark Mitchell <mark@codesourcery.com>
Sat, 28 Jan 2006 22:11:42 +0000 (22:11 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sat, 28 Jan 2006 22:11:42 +0000 (22:11 +0000)
PR c++/25999
* decl.c (start_preparsed_function): Call maybe_apply_pragma_weak
here, not ...
(start_function): ... here.
PR c++/25999
* g++.dg/ext/pragmaweak1.C: New test.

From-SVN: r110340

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/pragmaweak1.C [new file with mode: 0644]

index ad3be507d4ecf45dc6d2b67fbc2f9849ba7ab51b..107187937331b4d951684b874267d97eed92faeb 100644 (file)
@@ -1,3 +1,10 @@
+2006-01-28  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/25999
+       * decl.c (start_preparsed_function): Call maybe_apply_pragma_weak
+       here, not ...
+       (start_function): ... here.
+
 2006-01-28  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/25855
index e4be9e0f88c71a7681efbfc1bca3924d54d80a27..ef7ed3a4fcdc00d220fdaf32ef773e7404b0b644 100644 (file)
@@ -10287,6 +10287,17 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
            DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
        }
       fntype = TREE_TYPE (decl1);
+
+      /* If #pragma weak applies, mark the decl appropriately now.
+        The pragma only applies to global functions.  Because
+        determining whether or not the #pragma applies involves
+        computing the mangled name for the declaration, we cannot
+        apply the pragma until after we have merged this declaration
+        with any previous declarations; if the original declaration
+        has a linkage specification, that specification applies to
+        the definition as well, and may affect the mangled name.  */
+      if (!DECL_CONTEXT (decl1))
+       maybe_apply_pragma_weak (decl1);
     }
 
   /* Determine the ELF visibility attribute for the function.  We must
@@ -10458,10 +10469,6 @@ start_function (cp_decl_specifier_seq *declspecs,
   if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
     return 0;
 
-  /* If #pragma weak was used, mark the decl weak now.  */
-  if (global_scope_p (current_binding_level))
-    maybe_apply_pragma_weak (decl1);
-
   if (DECL_MAIN_P (decl1))
     /* main must return int.  grokfndecl should have corrected it
        (and issued a diagnostic) if the user got it wrong.  */
index 70b6deef740f86cab7a80a2ae1d4061bb2307cd9..5b40db880e2dcc70c44cf5180de25d6cea1baaf7 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-28  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/25999
+       * g++.dg/ext/pragmaweak1.C: New test.
+
 2006-01-28  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/25855
diff --git a/gcc/testsuite/g++.dg/ext/pragmaweak1.C b/gcc/testsuite/g++.dg/ext/pragmaweak1.C
new file mode 100644 (file)
index 0000000..68bf3fc
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/25999
+// { dg-final { scan-assembler-not "_Z3Foov" } }
+
+extern "C" {
+  void Foo();
+}
+#pragma weak Random_Symbol
+void Foo() { }
+