Skip to content

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

@firewave

Description

@firewave
#include <memory>

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

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

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

This fails with -std=c++23:

In file included from <source>: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<C::Impl>::operator()' requested here
  398 |           get_deleter()(std::move(__ptr));
      |           ^
<source>:14:4: note: in instantiation of member function 'std::unique_ptr<C::Impl>::~unique_ptr' requested here
   14 | C::C() = default;
      |    ^
<source>:14:10: note: in defaulted default constructor for 'C' first required here
   14 | C::C() = default;
      |          ^
<source>: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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationdiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issuerejects-valid

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions