llvm-project/clang/test/SemaOpenCLCXX/amdgpu-nullptr.clcpp
Timm Baeder 8704ca0fb8
[clang][ExprConst] Consider integer pointers of value 0 nullptr (#150164)
When casting a 0 to a pointer type, the IsNullPtr flag was always set to
false, leading to weird results like a pointer with value 0 that isn't a
null pointer.

This caused

```c++
struct B { const int *p;};
template<B> void f() {}
template void f<B{nullptr}>();
template void f<B{fold(reinterpret_cast<int*>(0))}>();
```

to be valid code, since nullptr and (int*)0 aren't equal. This seems
weird and GCC doesn't behave like this.
2025-08-06 16:49:00 +02:00

10 lines
255 B
Plaintext

// RUN: %clang_cc1 -triple amdgcn -cl-std=clc++ -verify %s
// expected-no-diagnostics
#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
static_assert(nullptr != fold(reinterpret_cast<private int*>(0)));
static_assert(nullptr == (private int *)0);