llvm / llvm/llvm-project

`-Wunused` false positive on constexpr function used to compute return type

Open
#196,564 0 comments 0 reactions 0 assignees View on GitHub
false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following produces a warning ([godbolt](https://godbolt.org/z/crKW95456)):

```
#include

static constexpr bool returnInt(int) { return true; }

template
std::conditional_t make() {
return T{};
}

int makeInt() { return make(); }
float makeFloat() { return make(); }
```

Warning:
```
function 'returnInt' is not needed and will not be emitted
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked Godbolt reproducer and confirm the -Wunused warning for the constexpr returnInt function used in the conditional return type. Trace the compiler's unused-function diagnostic for this case; done means the valid function no longer produces a false-positive warning while genuine unused functions still do.

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
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.