Issue 174131
Summary [Clang][Bytecode] void*-to-ptr casts from new allocations are broken
Labels clang
Assignees
Reporter keinflue
    The following program is well-formed in C++26:
```cpp
static_assert((delete (int*)(void*)new int, true));
static_assert((delete[] (int*)(void*)new int[2], true));
int main() {}
```
However, Clang with `-fexperimental-new-constant-interpreter  -std=c++2c` produces (https://godbolt.org/z/9oebej1f8):
```console
<source>:1:15: error: static assertion _expression_ is not an integral constant _expression_
    1 | static_assert((delete (int*)(void*)new int, true));
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:1:23: note: cast from 'void *' is not allowed in a constant _expression_ because the pointed object type 'int *' is not similar to the target type 'int'
    1 | static_assert((delete (int*)(void*)new int, true));
      | ^
<source>:2:15: error: static assertion _expression_ is not an integral constant _expression_
    2 | static_assert((delete[] (int*)(void*)new int[2], true));
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:2:25: note: cast from 'void *' is not allowed in a constant _expression_ because the pointed object type 'int *' is not similar to the target type 'int'
    2 | static_assert((delete[] (int*)(void*)new int[2], true));
      | ^
2 errors generated.
Compiler returned: 1
```
The note indicates that Clang falsely interprets the type of the pointed-to object to be `int*`, when it should be `int`, in both cases.

There is no issue without `-fexperimental-new-constant-interpreter`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to