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

            Bug ID: 109387
           Summary: "definition of explicitly-defaulted" error with
                    explicit template instantiation
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vittorio.romeo at outlook dot com
  Target Milestone: ---

Given this code:

    template <typename> struct S { S(); };
    // extern template struct S<int>;
    template <typename T> S<T>::S() = default;
    template S<int>::S();

GCC fails to compile with this error:

    error: definition of explicitly-defaulted 'S< <template-parameter-1-1>
>::S() 
           [with <template-parameter-1-1> = int]'
        3 | template <typename T> S<T>::S() = default;
          |                       ^~~~

Uncommenting the extern template fixes compilation. Clang compiles the original
code without any issue.

Live example on Compiler Explorer: 
- https://gcc.godbolt.org/z/YoPhvKnxa

Related StackOverflow thread:
- https://stackoverflow.com/questions/75913223
  • [Bug c++/109387] New: "... vittorio.romeo at outlook dot com via Gcc-bugs

Reply via email to