https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91304
Bug ID: 91304
Summary: maybe_unused attribute ignored on variable declared in
if declaration
Product: gcc
Version: 9.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
Reduced from StackOverflow (https://stackoverflow.com/q/57281641/2069064):
int f();
void g()
{
if ([[maybe_unused]] int i = f()) { }
}
Even though i is declared [[maybe_unused]], this still emits a warning:
<source>: In function 'void g()':
<source>:5:28: warning: unused variable 'i' [-Wunused-variable]
5 | if ([[maybe_unused]] int i = f()) { }
| ^