Code in constexpr if branch is incorrectly considered unused
Open
clang:diagnostics
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Hello,
the following code incorrectly produce a warning (with `-Wunneeded-internal-declaration`):
```cpp
constexpr bool B = false;
static auto foo(int x) -> int { // warning: Function 'foo' is not needed and will not be emitted
return x + 1;
}
int bar() {
if constexpr (B) {
return foo(1);
} else {
return 2;
}
}
```
Although `foo` is (statically) never called, removing it would cause the `true` branch to fail to compile.
Contributor guide
Assessment
This issue has not been assessed yet.