Issue 123545
Summary __builtin_launder complains about type completeness
Labels c++17, clang:frontend, diverges-from:gcc, diverges-from:msvc, diverges-from:edg
Assignees
Reporter hubert-reinterpretcast
    `std::launder` does not require that the type pointed to is complete. See https://wg21.link/ptr.launder.

Clang refuses to compile the following:
```cpp
#include <new>
struct A;
A *h(A *p) { return std::launder(p); }
```
which becomes (with multiple C++ standard libraries):
```cpp
struct A;
A *h(A *p) { return __builtin_launder(p); }
```

Online compiler link: https://godbolt.org/z/8KG98zaxW

### SOURCE (`<stdin>`):
```cpp
struct A;
A *h(A *p) { return __builtin_launder(p); }
```

### COMPILER INVOCATION:
```
clang++ -fsyntax-only -std=c++17 -xc++ -
```

### ACTUAL COMPILER OUTPUT:
```
<stdin>:2:21: error: incomplete type 'A' where a complete type is required
    2 | A *h(A *p) { return __builtin_launder(p); }
      |                     ^
<stdin>:1:8: note: forward declaration of 'A'
    1 | struct A;
      |        ^
1 error generated.
```

### EXPECTED COMPILER OUTPUT:
(clean compile)

### COMPILER VERSION INFO (`clang++ -v`):
```
clang version 20.0.0git (https://github.com/llvm/llvm-project.git dd42651295d0e1566b34104b007ad19865c57fcc)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to