-Wunused-variable incorrectly triggering on self-init
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider the following example:
```c
struct [[gnu::warn_unused]] S {
};
void func() {
struct S s1 = s1;
}
```
Language | Clang | GCC
---| --- | ---
C | No diagnostic | No diagnostic
C++ | Diagnostic | No diagnostic
https://godbolt.org/z/nafGTonor
I believe Clang's diagnostic in C++ is a false positive; mentioning the variable in its own initialization should silence the diagnostic because the variable is being used.
Contributor guide
Research direction
Start by reproducing the self-initialization example from the issue, using the linked Godbolt comparison to check Clang and GCC in both C and C++. Trace the -Wunused-variable diagnostic for the C++ case and identify the relevant compiler tests or diagnostic path. Done means the self-reference no longer produces a false positive while the warning remains correct for genuinely unused variables.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100