https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92367
Bug ID: 92367 Summary: spurious -Wunused-but-set-parameter warning with constexpr if in a template function Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: 60rntogo at gmail dot com Target Milestone: --- Created attachment 47171 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47171&action=edit g++ -v output The code template <bool b, typename T> constexpr T example(T i) { if constexpr (b) { return i; } else { return 0; } } int main() { example<false>(0); } compiled with g++ example.cpp -std=c++17 -Wunused-but-set-parameter yields example.cpp: In instantiation of ‘constexpr T example(T) [with bool b = false; T = int]’: example.cpp:16:20: required from here example.cpp:2:23: warning: parameter ‘i’ set but not used [-Wunused-but-set-parameter] 2 | constexpr T example(T i) | ~~^ The warning is raised even if example<true> is called in addition to example<false>. It is not raised if the template parameter T is replaced by int.