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

            Bug ID: 115283
           Summary: [14 Regression] "used but never defined" with extern
                    templates
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at hazardy dot de
  Target Milestone: ---

This reduced code does work with GCC 13, but with 14 I get the "used but never
defined" warning (and later undefined refernces, even tho the symbols are
emitted to the object files).

See https://godbolt.org/z/Gsz4x7d6h

#include <concepts>
#include <type_traits>

template<typename T>
class C
{
public:
    using ResultT = std::conditional_t<std::same_as<T, void>, T, T>;

    ResultT Result;

    C(ResultT result);
};

template<typename T>
C<T>::C(ResultT result)
    : Result{result}
{
    return;
}

extern template class C<bool>;

void foo()
{
    C<bool> r(true);
}

It is absolutely necessary to use the std::same_as for the conditional. If it
is replaced with true (or false) everything works. Even exchanging it with
sizeof(T) >= 2 works. std::is_same_v also works.

So maybe it's a bug in std::same_as?

Reply via email to