public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99066] New: non-weak definition emitted for explicit instantiation declaration
@ 2021-02-10 18:32 redi at gcc dot gnu.org
  2021-02-10 18:39 ` [Bug c++/99066] " jakub at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-10 18:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99066

            Bug ID: 99066
           Summary: non-weak definition emitted for explicit instantiation
                    declaration
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: link-failure
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

If two TUs both include a header that contains:

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>;

then we get a linker error, because both TUs define the npos constant:

/usr/bin/ld: /tmp/ccjy3Spq.o:(.rodata+0x0): multiple definition of
`basic_string<char>::npos'; /tmp/ccMQ33nr.o:(.rodata+0x0): first defined here


Shouldn't the static data member only have weak definitions, unless an explicit
instantiation definition is seen?

/* TU 1 */

#include "str.h"

int main()
{
  return e().f<true>();
}

/* TU 2 */

#include "str.h"


The assembly for both files contains:

        .globl  _ZN12basic_stringIcE4nposE
        .section        .rodata
        .align 4
        .type   _ZN12basic_stringIcE4nposE, @object
        .size   _ZN12basic_stringIcE4nposE, 4
_ZN12basic_stringIcE4nposE:
        .long   1

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-05-13 18:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 18:32 [Bug c++/99066] New: non-weak definition emitted for explicit instantiation declaration redi at gcc dot gnu.org
2021-02-10 18:39 ` [Bug c++/99066] " jakub at gcc dot gnu.org
2021-02-10 18:44 ` [Bug c++/99066] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
2021-02-10 18:55 ` jakub at gcc dot gnu.org
2021-04-04 15:59 ` jason at gcc dot gnu.org
2021-04-05 13:26 ` jason at gcc dot gnu.org
2021-04-05 13:29 ` cvs-commit at gcc dot gnu.org
2021-04-05 13:30 ` [Bug c++/99066] [8/9/10 " jason at gcc dot gnu.org
2021-04-05 18:58 ` redi at gcc dot gnu.org
2021-05-14  9:54 ` [Bug c++/99066] [9/10 " jakub at gcc dot gnu.org
2021-06-01  8:19 ` rguenth at gcc dot gnu.org
2022-05-13 17:14 ` cvs-commit at gcc dot gnu.org
2022-05-13 18:24 ` [Bug c++/99066] [9 " cvs-commit at gcc dot gnu.org
2022-05-13 18:26 ` jason at gcc dot gnu.org

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).