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

            Bug ID: 98485
           Summary: Symbols for identical constrained specializations have
                    different linkage
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: admin at maniacsvault dot net
  Target Milestone: ---

Created attachment 49861
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49861&action=edit
Minimal example code

When using multiple constrained specializations, the symbols generated have
different linkage based on the order the specializations are defined in the
file.  The first specialization will generate weak symbols as expected, the
second generates local symbols.

See attached example. S1 is a structure containing a static member function. 
S2 and S3 differ in some way that's detectable through concepts.  main.cpp can
only see these definitions so all it knows is that S1<T>::f() is forward
declared.  a.cpp and b.cpp include s1-defs.h which contains two basically
identical specializations of S1.  The first is applied for S2, the second for
S3.  a.cpp instantiates S1<S2>.  b.cpp instantiates S1<S3>.  These do not need
to be separate files, this was just done to make it easier to diff the two
outputs.  What you will notice is that a.o contains an externally visible
S1<S2>::f1 symbol.  b.o contains a local S1<S3>::f1 symbol.  Thus the program
can't link since main can't reference S1<S3>::f1.

Despite there being basically no difference in the two specializations the
linkage is unexpectedly different.  If the order of the two specializations in
s1-defs.h is reversed then S1<S2>::f1 will become problematic.

In s1-defs.h there's a USE_SINGLE define which when toggled uses if constexpr
instead of two specializations.  This effectively works around the issue and
the program links.

Reply via email to