[Bug c++/97914] New: -fno-delete-null-pointer-checks not working properly with constexpr

mfarazma.ext at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Nov 19 18:12:22 GMT 2020


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

            Bug ID: 97914
           Summary: -fno-delete-null-pointer-checks not working properly
                    with constexpr
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mfarazma.ext at gmail dot com
  Target Milestone: ---

Compiling this code:

```
constexpr int test(const int *arr) {
  if(arr == 0){
     //
   }
  return 5;
}

int main(){
  static constexpr int arr[] = {1,2,3};
  static constexpr int b =  test(arr);
  return 0;
}

```
With "g++ -fno-delete-null-pointer-check test.cc" generates this error:

error '(((const int*)(& arr)) == 0u)' is not a constant expression.  

Seems like an odd behaviour as clang++ is able to compile this successfully.
I have tested it on gcc 6, 7, 9 as well has "HEAD 11.0.0".


More information about the Gcc-bugs mailing list