https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119500
Bug ID: 119500 Summary: False positive "unused variable" warning on static variable templates with custom section placement Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: palchak at google dot com Target Milestone: --- A false "defined but not used" warning is emitted for static variable templates with custom section placement. Example source: ``` template<int ID> [[gnu::section(".custom")]] static int id = ID; int main() { return id<42>; } ``` Compile command: `g++ example.cc -o example -Wunused` Output: ``` example.cc:3:12: warning: ‘id<ID>’ defined but not used [-Wunused-variable] 3 | static int id = ID; | ^~ ``` The variable template is very clearly used. Compiler explorer reproduction: https://godbolt.org/z/hjsabfcfT