Clang rejects valid program saying implicit instantiation of undefined primary template
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following program is rejected by clang but accepted by both gcc and msvc. [Demo](https://godbolt.org/z/KKe9jT8E3)
```c++
#include
template
struct fn_ref_call;
template
struct fn_ref_call {
static constexpr bool enable = true;
};
template
struct fn_ref : private fn_ref_call {
private:
using base = fn_ref_call;
public:
template
requires (base::enable)
fn_ref(F* f){}
};
template
requires std::is_function_v
fn_ref(F *) -> fn_ref;
int fn(int) { return 3; }
int main() {
fn_ref f{&fn};
}
```
Clang says:
```
:12:25: error: implicit instantiation of undefined template 'fn_ref_call<>'
12 | struct fn_ref : private fn_ref_call {
| ^
:18:19: note: in instantiation of template class 'fn_ref<>' requested here
18 | requires (base::enable)
| ^
:18:19: note: while substituting template arguments into constraint expression here
18 | requires (base::enable)
| ^~~~~~~~~~~~
:30:12: note: while checking constraint satisfaction for template '' required here
30 | fn_ref f{&fn};
| ^
:30:12: note: while substituting deduced template arguments into function template '' [with S = (no value), F = int (int)]
:4:8: note: template is declared here
4 | struct fn_ref_call;
```
Contributor guide
Research direction
Start by reproducing the provided C++ program with Clang and compare its behavior with GCC and MSVC using the linked Godbolt demo. Trace constraint satisfaction and template instantiation around the `fn_ref` deduction guide and `fn_ref_call<>`; done means Clang accepts the valid program and a regression test covers this case.
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
- Clearly specified
- Newbie friendliness
- 38/100