[Bug c++/85827] false positive for -Wunused-but-set-variable because of constexpr-if
kretz at kde dot org
gcc-bugzilla@gcc.gnu.org
Fri May 18 12:47:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827
--- Comment #3 from Matthias Kretz <kretz at kde dot org> ---
But macros are different. They remove the code before the C++ parser sees it
(at least as-if). One great improvement of constexpr-if over macros is that all
the other branches are parsed and their syntax checked. E.g. it requires the
mentioned names to exist. This doesn't compile (cf.
https://godbolt.org/g/iCRPDv):
#ifdef HAVE_FOO
constexpr bool have_foo = true;
void foo();
#else
constexpr bool have_foo = false;
#endif
void f() {
if constexpr (have_foo) {
foo();
}
}
So, the frontend parses all branches anyway. It should be able to see that _2
and _3 are referenced in f<1>().
More information about the Gcc-bugs
mailing list