https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81676
Bug ID: 81676 Summary: Wrong warning with unused-but-set-parameter within 'if constexpr' Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: benni.buch at gmail dot com Target Milestone: --- template < typename T > int f(T v){ if constexpr(sizeof(T) == sizeof(int)){ return v; }else{ return 0; } } int main(){ f(0); f('a'); } This is a valid program which should not produce a warning. (Normal 'if' doesn't produce a warning either.) $ g++ -std=c++1z -Wunused-but-set-parameter gcc-warning.cpp gcc-warning.cpp: In instantiation of 'int f(T) [with T = char]': gcc-warning.cpp:12:7: required from here gcc-warning.cpp:2:9: warning: parameter 'v' set but not used [-Wunused-but-set-parameter] int f(T v){ ^ $ g++ --version g++ (GCC) 7.1.1 20170724 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.