llvm / llvm/llvm-project

Duplicate warning diagnostic produced by compiler for same code

Open
#224,474 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

Consider the following reduced test case originally derived from `clang/test/SemaTemplate/instantiate-member-initializers.cpp`:
```c++
template void C2() { ""; }
template void C2< int >();
```

When compiled, the compiler produces the warning diagnostic twice
https://godbolt.org/z/McYKrb7zj:
```

clang++: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
:1:30: warning: expression result unused [-Wunused-value]
1 | template void C2() { ""; }
| ^~
:1:30: warning: expression result unused [-Wunused-value]
1 | template void C2() { ""; }
| ^~
:2:15: note: in instantiation of function template specialization 'C2' requested here
2 | template void C2< int >();
| ^
2 warnings generated.
Compiler returned: 0
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reduced C++ case and compare it with clang/test/SemaTemplate/instantiate-member-initializers.cpp. Trace the diagnostic emitted for the unused expression during explicit function-template instantiation, then update or add the relevant test so the warning appears only once while the instantiation note remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.