| Issue |
175081
|
| Summary |
clang incorrectly emits -Wundefined-func-template warning in explicit block
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
nitnelave
|
Reproduction: https://godbolt.org/z/31YW38oT3
```cpp
struct NotDefaultable {
template <class T>
[[gnu::error("Members must be explicitly initialized.")]]
operator T() const;
};
struct M {
int x = NotDefaultable();
};
struct S {
explicit(requires(void (&f)(M)) { f({}); }) S() = default;
};
int main() { S _; }
```
```
$ clang++ -Werror -Wundefined-func-template -std=c++23
<source>:7:11: error: instantiation of function 'NotDefaultable::operator int<int>' required here, but no definition is available [-Werror,-Wundefined-func-template]
7 | int x = NotDefaultable();
| ^
<source>:4:3: note: forward declaration of template entity is here
4 | operator T() const;
| ^
<source>:7:11: note: add an explicit instantiation declaration to suppress this warning if 'NotDefaultable::operator int<int>' is explicitly instantiated in another translation unit
7 | int x = NotDefaultable();
| ^
1 error generated.
```
With Clang 20.1.0 and trunk as of this writing.
The only call to the default constructor of M is in the `explicit` specifier of S (the body is the same as `__is_implicitly_default_constructible_v<M>`). The `[[gnu::error(...)]]` is just there for motivation, it's not relevant to the error.
AFAIK, the `explicit` clause doesn't evaluate code, so it shouldn't count as an ODR-use (and the compiler is otherwise happy to compile the code). It would make sense that it also doesn't trigger the `-Wundefined-func-template` warning.
Related bug: https://github.com/llvm/llvm-project/issues/92486 with similar issues around the warning being too eager with virtual tables.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs