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

            Bug ID: 108617
           Summary: nullptr comparision in constexpr not constexpr when
                    using -fsanitize=returns-nonnull-attribute
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

Given the following source code

test.cpp:
constexpr bool test(const char* str) { return str == nullptr; }

int main() {
    static constexpr const char str[] = "";
    constexpr bool a = test(str);

    (void)a;
}

and compiling it with '-std=c++11 -fsanitize=returns-nonnull-attribute' gives
the following error:

error: '(((const char*)(& str)) == 0)' is not a constant expression
    1 | constexpr bool test(const char* str) { return str == nullptr; }

while compiling with only '-std=c++11' works fine.

Experimenting with compiler explorer it seems that every gcc version starting
with gcc-5.1 to the current trunk is affected by this.

https://godbolt.org/z/GEz6GYqo8
  • [Bug c++/108617] New: nullpt... andre.schackier at gmail dot com via Gcc-bugs

Reply via email to