public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10735] c++: extern template and static data member [PR99066]
@ 2022-05-13 17:14 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-05-13 17:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:20b503f1125c0b0a7f4b2bb1214d4a3cc6fd9f70

commit r10-10735-g20b503f1125c0b0a7f4b2bb1214d4a3cc6fd9f70
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Apr 4 23:32:32 2021 -0400

    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:
---
 gcc/cp/pt.c                                    |  5 ++++-
 gcc/testsuite/g++.dg/cpp0x/extern_template-6.C | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1746ddfa47c..a29e8fb7ad7 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 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" } }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-13 17:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 17:14 [gcc r10-10735] c++: extern template and static data member [PR99066] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).