Issue 131503
Summary [clang++] template nested class declaration works unexpectedly
Labels clang
Assignees
Reporter AnonymousPC
    (clang++, version=19.1.7, platform=MacOS)
See this code below

```cpp
template < class T >
concept my_concept = true;

template < class T >
struct my_class
{
    template < my_concept U >
    struct my_nested_class;
};

template < class T >
template < my_concept U >
#if defined(__GNUC__) and not defined(__clang__)
    struct my_class<T>::my_nested_class // *** Expected way, which works on gcc ***
#elifdef __clang__
    struct my_class<T>::my_nested_class<U> // *** In clang++ we must write in this way ***
#endif
    {

    };
```

When we declare as the first way in clang++, we get a compile-error like this:
```text
main.cpp:12:12: error: type constraint differs in template redeclaration
   12 | template < my_concept type2 >
      | ^
main.cpp:7:16: note: previous template declaration is here
    7 | template < my_concept type2 >
      |        
```
while declare as the second way is accepted in clang++.


However ***the first way is expected***, because when we declare a ***non-concept*** template nested class, it should be written like this:
```cpp

template < class T >
struct your_class
{
    template < class U >
    struct your_nested_class;
};

template < class T >
template < class U >
struct your_class<T>::your_nested_class /* clang++ requires no <U> here. Same do g++ */; 
```
and it should be along with the one with ***concept*** -constrained nested class.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to