summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-04-04 23:32:32 -0400
committerJason Merrill <jason@redhat.com>2022-05-13 14:05:20 -0400
commit950a97a5039c7b96602edfdf8984b5800f5837f3 (patch)
treed69ffe28a4a82dff7d8d5598ebba273df1a51066
parent200d477d3cb1593dbaa7739c6270e0a7f6c564cf (diff)
c++: extern template and static data member [PR99066]
'extern template' should mean that the relevant symbols are never emitted. But in this case we were assuming that DECL_EXTERNAL was already set on the variable, so we just needed to clear DECL_NOT_REALLY_EXTERN. Since DECL_EXTERNAL was not set, we emitted a definition of npos. gcc/cp/ChangeLog: PR c++/99066 * pt.c (mark_decl_instantiated): Set DECL_EXTERNAL. gcc/testsuite/ChangeLog: PR c++/99066 * g++.dg/cpp0x/extern_template-6.C: New test.
-rw-r--r--gcc/cp/pt.c5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/extern_template-6.C17
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4bae467fa71..b8aa7f8cb6a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -23171,7 +23171,10 @@ mark_decl_instantiated (tree result, int extern_p)
DECL_COMDAT (result) = 0;
if (extern_p)
- DECL_NOT_REALLY_EXTERN (result) = 0;
+ {
+ DECL_EXTERNAL (result) = 1;
+ DECL_NOT_REALLY_EXTERN (result) = 0;
+ }
else
{
mark_definable (result);
diff --git a/gcc/testsuite/g++.dg/cpp0x/extern_template-6.C b/gcc/testsuite/g++.dg/cpp0x/extern_template-6.C
new file mode 100644
index 00000000000..8aff3ae6b02
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/extern_template-6.C
@@ -0,0 +1,17 @@
+// PR c++/99066
+// { dg-do compile { target c++11 } }
+
+template <typename a> struct basic_string {
+ static const int npos = 1;
+};
+template <typename a> const int basic_string<a>::npos;
+
+struct e { template <bool> int f() const; };
+
+template <bool> int e::f() const {
+ return basic_string<char>::npos;
+}
+
+extern template class basic_string<char>;
+
+// { dg-final { scan-assembler-not "_ZN12basic_stringIcE4nposE" } }