[Bug c++/70194] [6 regression] missing -Waddress on constexpr pointer

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 11 17:37:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70194

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Below is a more comprehensive test case derived from one for another bug where
I noticed this problem.  It might be useful as a starting point for a test case
for this one.  Besides the regression it reveals a few minor inconsistencies in
the diagnostics that might be worth cleaning up:

1) For pointer to bool conversions, GCC issues warning: the address of ‘i’ will
always evaluate as ‘true’ [-Waddress]
2) For equality and inequality expressions, it issues warning: the address of
‘i’ will never be NULL [-Waddress]
3) For the equality and inequality expressions, GCC issues warning: ordered
comparison of pointer with integer zero [-Wextra], even though the comparison
is with a (null) pointer.
4) The -Wextra warning is not issued for inequality expressions where the null
pointer is cast to the type of the other operand (e.g., &i < (int*)0 is not
diagnosed).

int i;

namespace A {
const bool b0  = &i;
const bool b1  = !&i;
const bool b2  = &i == nullptr;
const bool b3  = nullptr == &i;
const bool b4  = &i != nullptr;
const bool b5  = nullptr != &i;
const bool b6  = &i <  nullptr;
const bool b7  = nullptr <  &i;
const bool b8  = &i <= nullptr;
const bool b9  = nullptr <= &i;
const bool b10 = &i >  nullptr;
const bool b11 = nullptr >  &i;
const bool b12 = &i >= nullptr;
const bool b13 = nullptr >= &i;
}

namespace B {
constexpr int *p = &i;

const bool bnullptr  = p;
const bool b1  = !p;
const bool b2  = p == nullptr;
const bool b3  = nullptr == p;
const bool b4  = p != nullptr;
const bool b5  = nullptr != p;
const bool b6  = p <  nullptr;
const bool b7  = nullptr <  p;
const bool b8  = p <= nullptr;
const bool b9  = nullptr <= p;
const bool b10 = p >  nullptr;
const bool b11 = nullptr >  p;
const bool b12 = p >= nullptr;
const bool b13 = nullptr >= p;
}


More information about the Gcc-bugs mailing list