Issue 60620
Summary libc++-16 regression: unique_ptr no longer works for incomplete type
Labels new issue
Assignees
Reporter vogelsgesang
    In 16.0.0-rc2, the following code

```
#include <memory>

struct ForwardDeclared;

struct MyStruct {
   std::unique_ptr<ForwardDeclared> member;
   MyStruct() {}
   ~MyStruct();
};
```

now produces the error

```
In file included from clang_regression.cpp:1:
In file included from external/clang_linux/include/c++/v1/memory:898:
In file included from external/clang_linux/include/c++/v1/__memory/shared_ptr.h:31:
external/clang_linux/include/c++/v1/__memory/unique_ptr.h:63:19: error: invalid application of 'sizeof' to an incomplete type 'ForwardDeclared'
    static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
                  ^~~~~~~~~~~
external/clang_linux/include/c++/v1/__memory/unique_ptr.h:297:7: note: in instantiation of member function 'std::default_delete<ForwardDeclared>::operator()' requested here
      __ptr_.second()(__tmp);
      ^
external/clang_linux/include/c++/v1/__memory/unique_ptr.h:263:75: note: in instantiation of member function 'std::unique_ptr<ForwardDeclared>::reset' requested here
  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
                                                                          ^
clang_regression.cpp:7:4: note: in instantiation of member function 'std::unique_ptr<ForwardDeclared>::~unique_ptr' requested here
   MyStruct() {}
   ^
clang_regression.cpp:3:8: note: forward declaration of 'ForwardDeclared'
struct ForwardDeclared;
       ^
1 error generated.
```

To my understanding, this is in violation of the standard which states:
* https://eel.is/c++draft/unique.ptr#general-4.sentence-3: The template parameter T of unique_­ptr may be an incomplete type[.](https://eel.is/c++draft/unique.ptr#general-4.sentence-3)
* https://eel.is/c++draft/unique.ptr#dltr.general-2: The template parameter T of default_­delete may be an incomplete type[.](https://eel.is/c++draft/unique.ptr#dltr.general-2.sentence-1)

Afaict, the two mandates:
* https://eel.is/c++draft/unique.ptr#dltr.dflt-3: T is a complete type for `default_­delete::operator()(T* ptr) const`
* https://eel.is/c++draft/unique.ptr#single.dtor-note-1: for `~unique_ptr`: [Note 1: The use of default_­delete requires T to be a complete type[.](https://eel.is/c++draft/unique.ptr#single.dtor-1.sentence-1) — end note]

do not apply for this code snippet, as I am not calling `~unique_ptr`. The destructor `~MyStruct()` is only declared, but not implemented in the header
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to