'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.
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);
--- /dev/null
+// 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" } }