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

            Bug ID: 124570
           Summary: bogus warning (-Waddress) on null-check of non-trivial
                    constant pointer expression
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matthijsvanduin at gmail dot com
  Target Milestone: ---

The following code:


int foo0;

constexpr int *get_foo( unsigned index )
{
        return index == 0 ? &foo0 : nullptr;
}

static_assert( get_foo(0) != nullptr );


results in a bogus warning that seems to think I'm null-testing a literal
mention of the object it points to, rather than an expression which absolutely
could have been NULL:

testcase.cc::8:27: warning: the address of 'foo0' will never be NULL
[-Waddress]
    8 | static_assert( get_foo(0) != nullptr );
      |                ~~~~~~~~~~~^~~~~~~~~~

Reply via email to