diff mbox

C++ PATCH for c++/64898 (wrongly mangled extern variable)

Message ID 54DD2BEF.3010300@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 12, 2015, 10:40 p.m. UTC
The test in write_mangled_name for a variable template failed to 
consider the case of a local extern declaration, which can have template 
info while not actually being a template instantiation.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 6f16507d6457d8a43fda62f1f78e9d2e3557f3de
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Feb 12 16:50:11 2015 -0500

    	PR c++/64898
    	* mangle.c (write_mangled_name): Fix test for variable template
    	instantiation.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 45377fc..fbf4bf2 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -682,7 +682,8 @@  write_mangled_name (const tree decl, bool top_level)
     }
   else if (VAR_P (decl)
 	   /* Variable template instantiations are mangled.  */
-	   && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
+	   && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
+		&& variable_template_p (DECL_TI_TEMPLATE (decl)))
 	   /* The names of non-static global variables aren't mangled.  */
 	   && DECL_EXTERNAL_LINKAGE_P (decl)
 	   && (CP_DECL_CONTEXT (decl) == global_namespace
diff --git a/gcc/testsuite/g++.dg/abi/mangle65.C b/gcc/testsuite/g++.dg/abi/mangle65.C
new file mode 100644
index 0000000..13169c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle65.C
@@ -0,0 +1,13 @@ 
+// PR c++/64898
+// { dg-final { scan-assembler-not "_Z6foovar" } }
+
+template <class> void f()
+{
+  extern int foovar;
+  foovar = 42;
+}
+
+int main()
+{
+  f<int>();
+}