Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make_unique cannot create struct of size of 0 due to default_delete's static_assert failure #54100

Closed
nickhuang99 opened this issue Feb 27, 2022 · 1 comment
Assignees
Labels
confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@nickhuang99
Copy link

nickhuang99 commented Feb 27, 2022

See code in compiler explorer: https://www.godbolt.org/z/z8xf31bG4

struct of size of 0 does have its usage and it is supported by GNU C (https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html). However, make_unique makes it impossible to create such an unique_ptr because its default_delete requires "A" must have non-zero size.

struct A{
alignas(int[0]) int ptr[0];
};
void test(){
	unique_ptr<A> ptr=make_unique<A>();
}

 error: static assertion failed: can't delete pointer to incomplete type
   83 |         static_assert(sizeof(_Tp)>0,
      |                       ~~~~~~~~~~~^~

I am not arguing that static_assert is reasonable. My point is that "make_shared" can actually deal this properly. i.e.

shared_ptr ptr=make_shared<A>();

gives no error at all.

p.s. I just realized that it is rather a library issue than a parser one as clang is directly using this library. Does clang plan to fix this library apart from GCC?

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Feb 27, 2022
@Quuxplusone Quuxplusone self-assigned this Feb 27, 2022
@Quuxplusone Quuxplusone added the confirmed Verified by a second party label Feb 27, 2022
@Quuxplusone
Copy link
Contributor

This is now https://reviews.llvm.org/D120633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

3 participants