[libcxx-commits] [PATCH] D128146: [libc++] Use uninitialized algorithms for vector

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 22 09:47:02 PDT 2022


philnik added a comment.

In D128146#3672050 <https://reviews.llvm.org/D128146#3672050>, @bgraur wrote:

> Hi folks,
>
> We have some code which compiles fine with the version previous to this patch and fails after.
> The code compiles fine with godbolt: https://gcc.godbolt.org/z/ToPGG5cMb
>
> But fails when built with `clang` containing this revision.
> Repro compilation command:
>
>   clang -stdlib=libc++ -std=gnu++17 \
>     -c /tmp/test.cc \
>     -o /tmp/test.o
>
> Compiler output:
>
>   /tmp/test.cc:5:17: error: assigning to 'float' from incompatible type 'Vx<float, 2>'
>     data[Index] = std::forward<LastArg>(last_arg);
>                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   /tmp/test.cc:22:5: note: in instantiation of function template specialization 'SetData<0, 2, float, Vx<float, 2> &>' requested here
>       SetData<0, Length, Element>(data_, std::forward<Args>(args)...);
>       ^
>   [redacted]/include/c++/v1/__memory/allocator.h:165:28: note: in instantiation of function template specialization 'Vx<float, 2>::Vx<Vx<float, 2> &>' requested here
>           ::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
>                              ^
>   [redacted]/include/c++/v1/__memory/allocator_traits.h:290:13: note: in instantiation of function template specialization 'std::allocator<Vx<float, 2>>::construct<Vx<float, 2>, Vx<float, 2> &>' requested here
>           __a.construct(__p, _VSTD::forward<_Args>(__args)...);
>               ^
>   [redacted]/include/c++/v1/__memory/uninitialized_algorithms.h:536:31: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<Vx<float, 2>>>::construct<Vx<float, 2>, Vx<float, 2> &, void>' requested here
>       allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), *__first1);
>                                 ^
>   [redacted]/include/c++/v1/vector:1012:22: note: in instantiation of function template specialization 'std::__uninitialized_allocator_copy<std::allocator<Vx<float, 2>>, Vx<float, 2> *, Vx<float, 2> *, Vx<float, 2> *>' requested here
>     __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
>                        ^
>   [redacted]/include/c++/v1/vector:1162:9: note: in instantiation of function template specialization 'std::vector<Vx<float, 2>>::__construct_at_end<Vx<float, 2> *>' requested here
>           __construct_at_end(__x.__begin_, __x.__end_, __n);
>           ^
>   /tmp/test.cc:35:16: note: in instantiation of member function 'std::vector<Vx<float, 2>>::vector' requested here
>     do_something(vertices);
>                  ^
>   1 error generated.

I think this is a bug in your code. https://godbolt.org/z/sv8YehKhY fails the same way, but without `std::vector`. BTW the simplest fix would be to add `Vx(Vx& v) : Vx(std::as_const(v)) {}`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128146



More information about the libcxx-commits mailing list