llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-18 regression] Compile error in out-of-line definition of constrained class template nested in a class template

Open ozaktash opened this issue 2 years ago • 6 comments

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).

ozaktash avatar Aug 07 '24 15:08 ozaktash

@llvm/issue-subscribers-clang-frontend

Author: None (ozaktash)

The following code doesn't compile on Clang 18 and further: ```cpp 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).

</details>

llvmbot avatar Aug 07 '24 15:08 llvmbot

Somewhat amusingly, Clang 18 fixed an issue present in Clang 17 regarding explicit specializations with similar code: https://godbolt.org/z/e7doYqe1d

AaronBallman avatar Aug 07 '24 17:08 AaronBallman

Fixed by #106585.

zyn0217 avatar Sep 21 '24 01:09 zyn0217

Requesting to reopen this issue as the fix was reverted and the error still reproduces in trunk.

MagentaTreehouse avatar Jan 16 '25 16:01 MagentaTreehouse

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 {

};

ilya-biryukov avatar Mar 28 '25 12:03 ilya-biryukov

Both of them are fixed in clang 21: https://godbolt.org/z/vh9oqeP7n https://godbolt.org/z/GYe66veqf

zyn0217 avatar Jul 18 '26 10:07 zyn0217