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

            Bug ID: 119898
           Summary: constexpr expansion of array null pointer check fails
                    with `-fno-delete-null-pointer-checks`
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vittorio.romeo at outlook dot com
  Target Milestone: ---

The following code

    constexpr int f(const int* p)
    {
        if (p == nullptr) { }
        return 0;
    }

    inline constexpr int a[] = {0};
    inline constexpr auto x = f(a);

compiled with the following flags

    -std=c++20 -fno-delete-null-pointer-checks

will result in 

    <source>:8:32:   in 'constexpr' expansion of 'f(((const int*)(& a)))'
    <source>:3:15: error: '(((const int*)(& a)) == 0)' is not a constant
expression
        3 |         if (p == nullptr) { }
          |             ~~^~~~~~~~~~
    Compiler returned: 1

Live example on Compiler Explorer:
- https://gcc.godbolt.org/z/nY445hGWv
  • [Bug c++/119898] New: const... vittorio.romeo at outlook dot com via Gcc-bugs

Reply via email to