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

Gleb Gladilov <liege.tenfold.5d at icloud dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |liege.tenfold.5d at icloud dot 
com

--- Comment #5 from Gleb Gladilov <liege.tenfold.5d at icloud dot com> ---
> (((const int*)(& arr)) == 0u) is indeed not a constant expression.  I suppose
> with -fno-delete-null-pointer-check C++ lacks a way to query for "no object"
> (since &arr is certainly the address of an object - it just may reside at
> address zero!).

Does it mean this bug is not considered an issue with G++, but rather C++
itself? Sounds like, this ticket will be closed without resolution as "Not an
issue". What surprises me w.r.t. this is that clang successfully compiles the
code, which suggests it's a bug on clang's side?

Not sure if it deserves a separate ticket or not, but I observed similar
behavior with recent G++ version (g++ 16.0.1 20260315) on following code
snippet:

```
template <auto Fn>
void wrap() {
    static_assert(Fn != nullptr);
}

template <typename T>
void foo() {}

int main() {
    wrap<foo<int>>();
    return 0;
}
```

It fails to compile via G++ with "‘(foo<int> != 0)’ is not a constant
expression" if -fno-delete-null-pointer-checks is used. 

What's also interesting is that if `foo` will be a free-function, instead of
function-template like this:

```
template <auto Fn>
void wrap() {
    static_assert(Fn != nullptr);
}

void foo() {}

int main() {
    wrap<foo>();
    return 0;
}
```

This would actually compile even with -fno-delete-null-pointer-checks. I don't
understand why -fno-delete-null-pointer-checks would allow free-function, but
not function-template here and it seems like a G++ bug to me.

Note: this issue was encountered at attempt to build recent LLVM trunk with
g++-13 (default version installable by apt on Ubuntu 24.04) and
-fno-delete-null-pointer-checks, which failed the build.

Reply via email to