[clang-18 regression] Compile error in out-of-line definition of constrained class template nested in a class template
The following code doesn't compile on Clang 18 and further:
template<typename>
concept Constrained = true;
template <typename T>
class C
{
template<Constrained>
class D;
};
template <typename T>
template <Constrained>
class C<T>::D
{
};
With the following message:
<source>:12:11: error: type constraint differs in template redeclaration
12 | template <Constrained>
| ^
<source>:7:14: note: previous template declaration is here
7 | template<Constrained>
| ^
1 error generated.
It compiles with Clang 17, GCC and MSVC (https://godbolt.org/z/r65o8sPjs).
@llvm/issue-subscribers-clang-frontend
Author: None (ozaktash)
template <typename T> class C { template<Constrained> class D; };
template <typename T> template <Constrained> class C<T>::D { };
With the following message:
<source>:12:11: error: type constraint differs in template redeclaration 12 | template <Constrained> | ^ <source>:7:14: note: previous template declaration is here 7 | template<Constrained> | ^ 1 error generated.
It compiles with Clang 17, GCC and MSVC (https://godbolt.org/z/r65o8sPjs).
</details>
Somewhat amusingly, Clang 18 fixed an issue present in Clang 17 regarding explicit specializations with similar code: https://godbolt.org/z/e7doYqe1d
Fixed by #106585.
Requesting to reopen this issue as the fix was reverted and the error still reproduces in trunk.
Another example from #133413, which I'll close as duplicate. Putting it here for reference to increase the chances of this being checked when the fix is in.
template <class FooT, class ArgT>
concept CanDo = requires (ArgT arg){
FooT::Do(arg);
};
struct Arg {
};
template <class T>
class Outer {
public:
template <class FooT>
requires CanDo<FooT, Arg>
class Inner;
};
template <class T>
template <class FooT>
requires CanDo<FooT, Arg>
class Outer<T>::Inner {
};
Both of them are fixed in clang 21: https://godbolt.org/z/vh9oqeP7n https://godbolt.org/z/GYe66veqf