https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126186
Bug ID: 126186
Summary: Parallel std::uninitialized_fill_n fails to compile
with non-copyable type
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: programmer00001h at gmail dot com
Target Milestone: ---
Problematic code (preprocessed version attached):
#include<execution>
#include<memory>
struct from_t{} constexpr inline from;
struct NonCopyable{
NonCopyable(from_t){}
NonCopyable(const NonCopyable&) = delete;
NonCopyable(NonCopyable&&) = default;
NonCopyable& operator=(const NonCopyable&) = delete;
NonCopyable& operator=(NonCopyable&&) = default;
~NonCopyable() = default;
};
int main(){
std::allocator<NonCopyable> alloc;
NonCopyable* p1 = alloc.allocate(8);
std::uninitialized_fill_n(p1,8,from); // ok
NonCopyable* p2 = alloc.allocate(8);
std::uninitialized_fill_n(std::execution::unseq,p2,8,from); //
ill-formed???
return 0;
}
Saved as bug.cpp, this erroneously fails to compile with `g++ bug.cpp
-std=c++26`.
Someone noted that in the implementation of the parallel uninitialized_fill_n,
two lambdas are passed to __pstl::__internal::__invoke_if_else, branching on
whether the input type is arithmetic. However, since function arguments are
always instantiated, this erroneously instantiates
__pstl::__internal::__brick_fill_n, which fails to compile for non-copyable
element types.
Error message:
In file included from /usr/include/c++/16/pstl/memory_impl.h:15,
from /usr/include/c++/16/pstl/algorithm_impl.h:20,
from /usr/include/c++/16/pstl/glue_execution_defs.h:50,
from /usr/include/c++/16/execution:41,
from ice.cpp:1:
/usr/include/c++/16/pstl/unseq_backend_simd.h: In instantiation of ‘_Index
__pstl::__unseq_backend::__simd_fill_n(_Index, _DifferenceType, const _Tp&)
[with _Index = NonCopyable*; _DifferenceType = int; _Tp = NonCopyable]’:
/usr/include/c++/16/pstl/algorithm_impl.h:2542:42: required from
‘_RandomAccessIterator
__pstl::__internal::__brick_fill_n(_RandomAccessIterator, _Size, const _Tp&,
std::true_type) [with _RandomAccessIterator = NonCopyable*; _Size = int; _Tp =
NonCopyable; std::true_type = std::true_type]’
2542 | return __unseq_backend::__simd_fill_n(__first, __count, __value);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/16/pstl/glue_memory_impl.h:201:60: required from
‘__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
_ForwardIterator> std::uninitialized_fill_n(_ExecutionPolicy&&,
_ForwardIterator, _Size, const _Tp&) [with _ExecutionPolicy = const
__pstl::execution::v1::unsequenced_policy&; _ForwardIterator = NonCopyable*;
_Size = int; _Tp = from_t;
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
_ForwardIterator> = NonCopyable*]’
201 | { return __pstl::__internal::__brick_fill_n(__begin,
__count, _ValueType(__value), __is_vector{}); });
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ice.cpp:17:30: required from here
17 | std::uninitialized_fill_n(std::execution::unseq,p2,8,from); //
ill-formed???
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/16/pstl/unseq_backend_simd.h:361:22: error: use of deleted
function ‘NonCopyable& NonCopyable::operator=(const NonCopyable&)’
361 | __first[__i] = __value;
| ~~~~~~~~~~~~~^~~~~~~~~
ice.cpp:8:18: note: declared here
8 | NonCopyable& operator=(const NonCopyable&) = delete;
| ^~~~~~~~
/usr/include/c++/16/pstl/unseq_backend_simd.h:361:22: note: use
‘-fdiagnostics-all-candidates’ to display considered candidates
361 | __first[__i] = __value;
| ~~~~~~~~~~~~~^~~~~~~~~
Output of gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-gcc-major-version-only
--with-linker-hash-style=gnu --with-system-zlib --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp
--disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.1.1 20260625 (GCC)