Static variable template with deduced type within a class template is rejected
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider the following example:
```cpp
template
struct A {
template
static constexpr auto value = 5;
};
decltype(A::value) x{};
```
Clang has been rejecting this since 9 (https://godbolt.org/z/8xMYEW51a), but other compilers accept (https://godbolt.org/z/Wcnz4K8f6):
```
:13:37: error: illegal initializer type 'decltype(A::value)' (aka 'const auto')
13 | decltype(A::value) x{};
| ^
```
Consider the following example derived from the first one that adds a type alias:
```cpp
template
struct A {
template
static constexpr auto value = 5;
using result_t = decltype(value);
};
decltype(A::value) x{};
```
Clang has been rejecting this since 12 with the same diagnostic as above (https://godbolt.org/z/zqaExM1a8), but other compilers accept (https://godbolt.org/z/zxx1acje6). Since 21 we issue a different diagnostic:
```
:9:19: error: the type of variable template specialization 'value' declared with deduced type 'const auto' depends on itself
9 | decltype(A::value) x{};
| ^
```
Related: #147992, #134526, #45408
Contributor guide
Research direction
Start by reducing and running the two C++ reproducer examples, then read related issues #147992, #134526, and #45408 to understand the existing context. Compare Clang's diagnostics and behavior with the other compilers shown in the linked Compiler Explorer cases; done means the examples are handled consistently with the intended standard behavior and covered by an appropriate compiler test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100