Bogus error "type of variable template specialization [...] declared with deduced type [...] depends on itself"
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Test case:
```c++
#include
struct dummy {
};
template struct real { A a; };
template struct Tests {
template static constexpr dummy obj = {};
const int reg = [] {
using X = decltype(obj<0>); // #1
(void)&obj<0>; // #2
return 0;
}();
template
requires(Tmp == 0)
static constexpr real obj = {0};
};
int main() { Tests{}; }
```
```sh
❯ clang++-23 -std=c++26 -O2 -Wall clang_issue.cpp
clang_issue.cpp:13:12: error: the type of variable template specialization 'obj<0>' declared with deduced type 'const real'
depends on itself
13 | (void)&obj<0>;
| ^
clang_issue.cpp:11:22: note: while substituting into a lambda expression here
11 | const int reg = [] {
| ^
clang_issue.cpp:22:25: note: in instantiation of default member initializer 'Tests::reg' requested here
22 | int main() { Tests{}; }
| ^
clang_issue.cpp:22:14: warning: expression result unused [-Wunused-value]
22 | int main() { Tests{}; }
| ^ ~~
1 warning and 1 error generated.
```
Comment line `#1` or swap lines `#1` and `#2` and the code is accepted. GCC always accepts.
The error message is not helpful. But I very much suspect Clang is incorrect to reject this program.
Contributor guide
Research direction
Start with the standalone C++ reproducer and run the shown clang++-23 command, comparing behavior when line #1 is removed or the two lines are swapped. Trace Clang's handling of the variable template specialization, lambda instantiation, and dependent type deduction. Done means the valid program is accepted without the bogus self-dependency error while the relevant diagnostics remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100