Skip to content

vector<int*const> fails to build with an error in C++20 mode #73664

Closed as not planned
@ilya-biryukov

Description

@ilya-biryukov

This code should technically be allowed per C++20 standard (int *const meets the requirement of MoveInsertable and Erasable):

#include <vector>

int main() {
    std::vector<int* const> foo;
    foo.push_back(nullptr);
}

However, when I build with clang++ -std=c++20 using libc++ from close to head, I get a compiler error:

../include/c++/v1/__algorithm/move.h:42:17: error: cannot assign to return value because function 'operator*' returns a const value
   42 |       *__result = _IterOps<_AlgPolicy>::__iter_move(__first);
...
<source>:5:9: note: in instantiation of member function 'std::vector<const int *const>::push_back' requested here
    5 |     foo.push_back(nullptr);

Compiling with -std=c++17 produces no errors. I believe this is somehow related to allocators, because specifying -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS and -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION with -std=c++20 makes this code compile again.

See godbolt too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions