From: Jason Merrill Date: Mon, 5 Apr 2021 03:32:32 +0000 (-0400) Subject: c++: extern template and static data member [PR99066] X-Git-Tag: releases/gcc-10.4.0~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20b503f1125c0b0a7f4b2bb1214d4a3cc6fd9f70;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1746ddfa47c9..a29e8fb7ad75 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24041,7 +24041,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 000000000000..8aff3ae6b02e --- /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 struct basic_string { + static const int npos = 1; +}; +template const int basic_string::npos; + +struct e { template int f() const; }; + +template int e::f() const { + return basic_string::npos; +} + +extern template class basic_string; + +// { dg-final { scan-assembler-not "_ZN12basic_stringIcE4nposE" } }