llvm / llvm/llvm-project

Code in constexpr if branch is incorrectly considered unused

Open
#184,396 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.