llvm / llvm/llvm-project

Clang's `-Wunused-template` false positive from requires clause

Open
#218,429 2 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`-Wunused-template` was recently added to `-Wunused`, but it seems to have a false positive.

https://cpp.compiler-explorer.com/z/e4b1Gr7jn

```c++
static void O(char /*arg*/) {}
static void O(int /*arg*/) {}

template
static void A(T /*arg*/) {}

template
static constexpr bool BT = requires {
A(O);
};

int main() {
if constexpr (BT) {
O('x');
O(42);
}
}
```

Produces:

```
:5:13: warning: unused function template 'A' [-Wunused-template]
5 | static void A(T /*arg*/) {}
| ^
1 warning generated.
```

While *technically* the require clause will compile even without the template, it still uses the template to change its result.

Contributor guide

Open the contributing guide

Research direction

Start with the reduced C++ reproducer in the issue and investigate Clang's -Wunused-template diagnostic handling for requires expressions. Compare the warning with whether the template affects the requires result, then add or update a regression test so this case no longer reports a false positive.

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
Active
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.