Skip to content

[libc++] Falsely rejected code for std::unique_ptr because __compressed_pair requires different types. #91266

Closed
@SainoNamkho

Description

@SainoNamkho

As shown in https://godbolt.org/z/4K6q9bo3e, only libc++ refuses to compile the following code

#include <memory>
#include <any>

void f(std::any) {}

std::unique_ptr<decltype(f), decltype(f)*> p(f, f);

I've not found anywhere in the draft saying this should be rejected.

  1. Why does __compressed_pair require the two template arguments to be distinct and the _CanBeEmptyBase traits? If they make it unable to compress, then an uncompressed layout is automatically produced, with no need to be explicitly rejected. And the indices used by __compressed_pair_elem suggest that it handles same types correctly.
  2. If it is reasonable to keep the implementation of __compressed_pair, is it a good solution to change unique_ptr into use something like conditional_t<same_as<pointer, deleter_type>, __compressed_pair<<pointer, deleter_type>, ...>?

Metadata

Metadata

Assignees

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.rejects-valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions