https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108395
Bug ID: 108395 Summary: [C2x] Bogus -Wunused-but-set-variable when returning constexpr variable Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: p...@gcc-bugzilla.mail.kapsi.fi Target Milestone: --- Hi. It appears if constexpr variable, declared at block scope, is used verbatim as a return value GCC emits a bogus -Wunused-but-set-variable. Using version `13.0.0 20230113 (experimental)'. # echo 'int f() { constexpr int v = 0; return v; }' | gcc -c -xc -std=c2x -Wall -Wextra - <stdin>: In function 'f': <stdin>:1:25: warning: variable 'v' set but not used [-Wunused-but-set-variable] As a workaround any operation on v (cast, effectively-no-op arithmetics etc.) or maybe_unused attribute (or file scope) can be used.