GCC/Clang disagree on constrained partial template specialization with out-of-line member definition

Viewed 98

Consider the following code which creates a partial template specialization that is constrained by a concept.

#include <concepts>

template <typename T>
struct Foo { };

template<typename T>
requires std::integral<T>
struct Foo<T> {
    static void bar();
};

template<typename T>
requires std::integral<T>
void Foo<T>::bar() { }

int main() {
    Foo<int>::bar();
}

This code compiles without error using gcc 10.2 and MSVC 19.27. However, clang 11.0 errors at the out-of-line definition of bar():

<source>:13:15: error: requires clause differs in template redeclaration

requires std::integral<T>

              ^

<source>:3:1: note: previous template declaration is here

template <typename T>

If the definition is moved in-line into the partially specialized class, clang does not error.

Is this a bug in clang or does the standard disallow the above code for some reason?

Link to code in godbolt: https://godbolt.org/z/orsWaP

0 Answers
Related