[libcxx-commits] [libcxx] [libc++] constexpr deque (PR #129368)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 16 18:15:08 PDT 2025
frederick-vs-ja wrote:
> Im running into another case, an example of such case is located in the file `libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp`
>
> When doing assertion `assert(c2 == c3)` for min_allocator, I ran into this error below. It seems the function is marked as constexpr but has not been tested for constant expression before.
>
> In this case, we are trying to initialize `min_pointer<const min_pointer<const MoveOnly, ID>, ID>` from a `min_pointer<const min_pointer<MoveOnly, ID>, ID>`, the constructor `min_pointer(min_pointer<const void, ID> p)` is invoked, but the static cast fails.
>
> The constructor `min_pointer(min_pointer<T, ID> p)` fails because `min_pointer<T, ID>` in this case is `min_pointer<min_pointer<const MoveOnly, ID>, ID>`, and there is no conversion to convert `min_pointer<const min_pointer<MoveOnly, ID>, ID>` to it.
>
> @frederick-vs-ja Do you know how to fix this?
>
> ```
> | /Users/nguyennhat/Desktop/llvm-2/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp:107:17: error: static assertion expression is not an integral constant expression
> # | 107 | static_assert(test());
> # | | ^~~~~~
> # | /Users/nguyennhat/Desktop/llvm-2/libcxx/test/support/min_allocator.h:322:85: note: cast from 'const void *' is not allowed in a constant expression because the pointed object type 'min_pointer<MoveOnly>' is not similar to the target type 'const min_pointer<const MoveOnly>'
> # | 322 | TEST_CONSTEXPR_CXX14 explicit min_pointer(min_pointer<const void, ID> p) : ptr_(static_cast<const T*>(p.ptr_)) {}
> # | | ^
> # | /Users/nguyennhat/Desktop/llvm-2/build/runtimes/runtimes-bins/libcxx/test-suite-install/include/c++/v1/deque:729:32: note: in call to 'min_pointer({&{*new min_pointer<MoveOnly>[1]#16}[0]})'
> # | 729 | __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
> # | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> # | /Users/nguyennhat/Desktop/llvm-2/build/runtimes/runtimes-bins/libcxx/test-suite-install/include/c++/v1/deque:2570:43: note: in call to '__x.begin()'
> # | 2570 | return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
> # | | ^~~~~~~~~~~
> # | /Users/nguyennhat/Desktop/llvm-2/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp:94:12: note: in call to 'operator==<MoveOnly, min_allocator<MoveOnly>>(c2, c3)'
> # | 94 | assert(c2 == c3);
> ```
I opened #136067 for the type issue with `const_iterator`.
https://github.com/llvm/llvm-project/pull/129368
More information about the libcxx-commits
mailing list