[Bug c++/69681] C/C++ FEs do not consider comparisons of distinct function pointers to be constant expressions
ppalka at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Feb 5 02:12:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69681
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> I don't think "(int)(&foo != &bar)" is a valid constant integer expression
> in either C or C++. (definitely not in C). This is why GCC rejects it.
Oops, good point. It is not a valid integer-constant-expression, but from what
I read it is a valid constant-expression, in both C and C++. Thus, instead of
doing
int x[(int)(&foo != &bar)];
to check that the comparison evaluates to a constant, it is more correct to do
const int x = &foo != &bar;
in the C frontend, and
constexpr int x = &foo != &bar;
in the C++ frontend. Either way, such code still fails to compile.
More information about the Gcc-bugs
mailing list