llvm / llvm/llvm-project

potentially incorrect `error: invalid application of 'sizeof' to an incomplete type` with `-std=c++23`

Open
#175,483 4 comments 1 reaction 0 assignees View on GitHub
c++23 clang:frontend constexpr diverges-from:gcc diverges-from:msvc rejects-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```cpp
#include

class C
{
public:
C();
~C();

private:
struct Impl;
std::unique_ptr mImpl;
};

C::C() = default;
C::~C() = default;
struct C::Impl {};
```

This fails with `-std=c++23`:
```
In file included from :1:
In file included from /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/memory:80:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/bits/unique_ptr.h:90:16: error: invalid application of 'sizeof' to an incomplete type 'C::Impl'
90 | static_assert(sizeof(_Tp)>0,
| ^~~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/bits/unique_ptr.h:398:4: note: in instantiation of member function 'std::default_delete::operator()' requested here
398 | get_deleter()(std::move(__ptr));
| ^
:14:4: note: in instantiation of member function 'std::unique_ptr::~unique_ptr' requested here
14 | C::C() = default;
| ^
:14:10: note: in defaulted default constructor for 'C' first required here
14 | C::C() = default;
| ^
:10:12: note: forward declaration of 'C::Impl'
10 | struct Impl;
| ^
```

It builds fine with all previous standards as well as GCC and MSVC using C++23.

https://godbolt.org/z/9rx9j3KhP

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.