[libcxx-commits] [PATCH] D68365: [libc++] Implement P1004R2 (constexpr std::vector)

Alexander Kornienko via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 10 00:36:27 PDT 2022


alexfh added a comment.

This commit breaks some code in c++20 mode: https://gcc.godbolt.org/z/h7j93MGsb

Specifically, move assignment of a vector of incomplete type can't be compiled now. Is this expected?

  #include <vector>
  
  struct S {
    S(S&& s) { v = std::move(s.v); }
    struct Inner;
    std::vector<Inner> v;
  };
  
  struct S::Inner {
    int a;
  };



  In file included from <source>:1:
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:540:52: error: arithmetic on a pointer to an incomplete type 'S::Inner'
          {return static_cast<size_type>(__end_cap() - this->__begin_);}
                                         ~~~~~~~~~~~ ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:760:56: note: in instantiation of member function 'std::vector<S::Inner>::capacity' requested here
        __annotate_contiguous_container(data(), data() + capacity(),
                                                         ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:431:7: note: in instantiation of member function 'std::vector<S::Inner>::__annotate_delete' requested here
        __annotate_delete();
        ^
  <source>:4:3: note: in instantiation of member function 'std::vector<S::Inner>::~vector' requested here
    S(S&& s) { v = std::move(s.v); }
    ^
  <source>:5:10: note: forward declaration of 'S::Inner'
    struct Inner;
           ^
  In file included from <source>:1:
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:760:54: error: arithmetic on a pointer to an incomplete type 'const value_type' (aka 'const S::Inner')
        __annotate_contiguous_container(data(), data() + capacity(),
                                                ~~~~~~ ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:431:7: note: in instantiation of member function 'std::vector<S::Inner>::__annotate_delete' requested here
        __annotate_delete();
        ^
  <source>:4:3: note: in instantiation of member function 'std::vector<S::Inner>::~vector' requested here
    S(S&& s) { v = std::move(s.v); }
    ^
  <source>:5:10: note: forward declaration of 'S::Inner'
    struct Inner;
           ^
  In file included from <source>:1:
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:833:64: error: arithmetic on a pointer to an incomplete type 'S::Inner'
          __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
                                                                 ^ ~~~~~~~~~~~~~~~~
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:827:29: note: in instantiation of member function 'std::vector<S::Inner>::__base_destruct_at_end' requested here
    void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
                              ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:436:9: note: in instantiation of member function 'std::vector<S::Inner>::__clear' requested here
          __clear();
          ^
  <source>:4:3: note: in instantiation of member function 'std::vector<S::Inner>::~vector' requested here
    S(S&& s) { v = std::move(s.v); }
    ^
  <source>:5:10: note: forward declaration of 'S::Inner'
    struct Inner;
           ^
  In file included from <source>:1:
  In file included from /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:296:
  In file included from /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/__split_buffer:20:
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/__memory/allocator.h:128:58: error: invalid application of 'sizeof' to an incomplete type 'S::Inner'
              _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
                                                           ^~~~~~~~~~~
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/__memory/allocator_traits.h:282:13: note: in instantiation of member function 'std::allocator<S::Inner>::deallocate' requested here
          __a.deallocate(__p, __n);
              ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:437:25: note: in instantiation of member function 'std::allocator_traits<std::allocator<S::Inner>>::deallocate' requested here
          __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
                          ^
  <source>:4:3: note: in instantiation of member function 'std::vector<S::Inner>::~vector' requested here
    S(S&& s) { v = std::move(s.v); }
    ^
  <source>:5:10: note: forward declaration of 'S::Inner'
    struct Inner;
           ^
  In file included from <source>:1:
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:537:53: error: arithmetic on a pointer to an incomplete type 'S::Inner'
          {return static_cast<size_type>(this->__end_ - this->__begin_);}
                                         ~~~~~~~~~~~~ ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:636:32: note: in instantiation of member function 'std::vector<S::Inner>::size' requested here
          size_type __old_size = size();
                                 ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:953:9: note: in instantiation of member function 'std::vector<S::Inner>::clear' requested here
          clear();
          ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:1314:5: note: in instantiation of member function 'std::vector<S::Inner>::__vdeallocate' requested here
      __vdeallocate();
      ^
  /opt/compiler-explorer/clang-trunk-20220809/bin/../include/c++/v1/vector:1288:5: note: in instantiation of member function 'std::vector<S::Inner>::__move_assign' requested here
      __move_assign(__x, integral_constant<bool,
      ^
  <source>:4:16: note: in instantiation of member function 'std::vector<S::Inner>::operator=' requested here
    S(S&& s) { v = std::move(s.v); }
                 ^
  <source>:5:10: note: forward declaration of 'S::Inner'
    struct Inner;
           ^
  5 errors generated.
  Compiler returned: 1


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68365/new/

https://reviews.llvm.org/D68365



More information about the libcxx-commits mailing list