clang reject valid code
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
It is hard to describe this issue, the minimum reproduction code:
```c++
int test(int*);
template
struct A {
template
static auto f(U* p) ->
decltype(test(p), A()) { return A(); }
};
template
auto g(Args&&... args)
->decltype(A::f(args...)) {
return A::f(args...);
}
A h(int* p) { return g(p); }
```
gcc is ok, see: https://godbolt.org/z/ehzezE75d
clang compile error:
```
:6:23: error: invalid use of incomplete type 'A'
6 | decltype(test(p), A()) { return A(); }
| ^~~
:10:12: note: in instantiation of template class 'A' requested here
10 | ->decltype(A::f(args...)) {
| ^
:3:8: note: definition of 'A' is not complete until the closing '}'
3 | struct A {
| ^
:10:20: error: no member named 'f' in 'A'
10 | ->decltype(A::f(args...)) {
| ^
:11:20: error: no member named 'f' in 'A'
11 | return A::f(args...);
| ^
:13:27: error: no matching function for call to 'g'
13 | A h(int* p) { return g(p); }
| ^
```
Contributor guide
Research direction
Run the minimal C++ reproduction with Clang and GCC, using the linked Compiler Explorer result as the comparison point. Investigate Clang's handling of the dependent trailing return type and incomplete class during template instantiation; done means Clang accepts this valid program without the reported diagnostics.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100