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

            Bug ID: 117052
           Summary: GCC accepts declaring an instantiation of member
                    template in the wrong scope
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

This should not compile:

struct Base { template <typename T> static void f(); };
struct Derived : public Base {};
template <> void Derived::f<int>() {}

Clang rejects it. MSVC incorrectly accepts it too. See
https://conformance.godbolt.org/z/TEornTf5o.

GCC correctly rejects it if the function is either non-static or non-template.

error: template-id 'f<int>' for 'void Derived::f()' does not match any template
declaration

Found this by accident, trying to understand why some variables and types that
should have been in Derived's scope weren't being found in the definition of
the function.

Reply via email to