public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-7986] c++: extern template and static data member [PR99066] Date: Mon, 5 Apr 2021 13:29:27 +0000 (GMT) [thread overview] Message-ID: <20210405132927.BD461385803F@sourceware.org> (raw) https://gcc.gnu.org/g:bd89b8fe9efbdf0a95d827553d1a84fd3cefaa16 commit r11-7986-gbd89b8fe9efbdf0a95d827553d1a84fd3cefaa16 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 1d19a59dd62..396e622c4db 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24204,7 +24204,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" } }
reply other threads:[~2021-04-05 13:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210405132927.BD461385803F@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).