public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107906] New: Function template specialization given weak rather than local symbol
@ 2022-11-29  6:44 herring at lanl dot gov
  2022-11-29  8:19 ` [Bug c++/107906] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: herring at lanl dot gov @ 2022-11-29  6:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107906
           Summary: Function template specialization given weak rather
                    than local symbol
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: herring at lanl dot gov
  Target Milestone: ---

Current trunk, given <https://godbolt.org/z/aoMecfhqb>

  template<class> using X=int;
  namespace {
    template<class> using Y=int;
  }

  template<template<class> class Q> void f() {}
  template void f<X>();

  void (*fp)()=f<Y>;

emits weak symbols for both specializations of f, despite the fact that a
different "void f<(anonymous namespace)::Y>()" might be defined in another
translation unit (perhaps as an explicit specialization).

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

* [Bug c++/107906] Function template specialization given weak rather than local symbol
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
@ 2022-11-29  8:19 ` rguenth at gcc dot gnu.org
  2022-11-29  8:57 ` [Bug c++/107906] linkage of template not taken into account pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-29  8:19 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ABI
   Last reconfirmed|                            |2022-11-29
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
With

namespace {
  class Y {};
}

template<class X>
struct Z
{
  Z() {}
};

Z<Y> z;

'z' is local and the CTOR is as well.  So it's somehow a mistake of
function templates.

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

* [Bug c++/107906] linkage of template not taken into account
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
  2022-11-29  8:19 ` [Bug c++/107906] " rguenth at gcc dot gnu.org
@ 2022-11-29  8:57 ` pinskia at gcc dot gnu.org
  2022-11-30 15:46 ` herring at lanl dot gov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-29  8:57 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.1.2
            Summary|Function template           |linkage of template not
                   |specialization given weak   |taken into account
                   |rather than local symbol    |

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>specializations 
That is not a specialization, that is an instantiation.

>So it's somehow a mistake of function templates.

It is not function templates which is causing the issue.  Rather than it is
template taking another template type which is causing issues.

E.g.
```
namespace {
  template<class>
  struct Y{};
}

template<template<class> class Q> 
struct f{
  f(){__builtin_printf("Hello.\n");}
};
f<Y> z;
```
f<Y>'s ctor is emitted as a weak symbol.

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

* [Bug c++/107906] linkage of template not taken into account
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
  2022-11-29  8:19 ` [Bug c++/107906] " rguenth at gcc dot gnu.org
  2022-11-29  8:57 ` [Bug c++/107906] linkage of template not taken into account pinskia at gcc dot gnu.org
@ 2022-11-30 15:46 ` herring at lanl dot gov
  2022-11-30 15:52 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: herring at lanl dot gov @ 2022-11-30 15:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from S. Davis Herring <herring at lanl dot gov> ---
Thanks for identifying the true common thread.

> That is not a specialization, that is an instantiation.

The standard uses specialization for every "version" of a template; some are
just "explicit specializations".  It uses (explicit/implicit) instantiation
only for the process of creating one.  (I realize that just about no one else
uses the words that way.)

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

* [Bug c++/107906] linkage of template not taken into account
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
                   ` (2 preceding siblings ...)
  2022-11-30 15:46 ` herring at lanl dot gov
@ 2022-11-30 15:52 ` redi at gcc dot gnu.org
  2022-12-29  3:07 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-30 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Some of us try to explain it:
https://gcc.gnu.org/pipermail/libstdc++/2022-November/055032.html

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

* [Bug c++/107906] linkage of template not taken into account
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
                   ` (3 preceding siblings ...)
  2022-11-30 15:52 ` redi at gcc dot gnu.org
@ 2022-12-29  3:07 ` pinskia at gcc dot gnu.org
  2023-12-21 18:53 ` cvs-commit at gcc dot gnu.org
  2023-12-21 18:58 ` [Bug c++/107906] linkage of alias " ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-29  3:07 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 70413.

*** This bug has been marked as a duplicate of bug 70413 ***

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

* [Bug c++/107906] linkage of template not taken into account
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
                   ` (4 preceding siblings ...)
  2022-12-29  3:07 ` pinskia at gcc dot gnu.org
@ 2023-12-21 18:53 ` cvs-commit at gcc dot gnu.org
  2023-12-21 18:58 ` [Bug c++/107906] linkage of alias " ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-21 18:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:7226f825db049517b64442a40a6387513febb8f9

commit r14-6789-g7226f825db049517b64442a40a6387513febb8f9
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Dec 21 13:53:43 2023 -0500

    c++: visibility wrt template and ptrmem targs [PR70413]

    When constraining the visibility of an instantiation, we weren't
    properly considering the visibility of PTRMEM_CST and TEMPLATE_DECL
    template arguments.

    This patch fixes this.  It turns out we don't maintain the relevant
    visibility flags for alias templates (e.g. TREE_PUBLIC is never set),
    so continue to ignore alias template template arguments for now.

            PR c++/70413
            PR c++/107906

    gcc/cp/ChangeLog:

            * decl2.cc (min_vis_expr_r): Handle PTRMEM_CST and TEMPLATE_DECL
            other than those for alias templates.

    gcc/testsuite/ChangeLog:

            * g++.dg/template/linkage2.C: New test.
            * g++.dg/template/linkage3.C: New test.
            * g++.dg/template/linkage4.C: New test.
            * g++.dg/template/linkage4a.C: New test.

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

* [Bug c++/107906] linkage of alias template not taken into account
  2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
                   ` (5 preceding siblings ...)
  2023-12-21 18:53 ` cvs-commit at gcc dot gnu.org
@ 2023-12-21 18:58 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-21 18:58 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |---
             Status|RESOLVED                    |NEW
                 CC|                            |ppalka at gcc dot gnu.org
            Summary|linkage of template not     |linkage of alias template
                   |taken into account          |not taken into account

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reopening to track the specific case of alias template template argument
linkage

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

end of thread, other threads:[~2023-12-21 18:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-29  6:44 [Bug c++/107906] New: Function template specialization given weak rather than local symbol herring at lanl dot gov
2022-11-29  8:19 ` [Bug c++/107906] " rguenth at gcc dot gnu.org
2022-11-29  8:57 ` [Bug c++/107906] linkage of template not taken into account pinskia at gcc dot gnu.org
2022-11-30 15:46 ` herring at lanl dot gov
2022-11-30 15:52 ` redi at gcc dot gnu.org
2022-12-29  3:07 ` pinskia at gcc dot gnu.org
2023-12-21 18:53 ` cvs-commit at gcc dot gnu.org
2023-12-21 18:58 ` [Bug c++/107906] linkage of alias " ppalka 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).