Describe the bug
The following program doesn't compile with MSVC STL due to narrowing conversion in list-initialization.
(originally discovered by mq白 (@Mq-b) in Mq-b/Loser-HomeWork@099c66a)
#include <execution>
#include <numeric>
#include <string>
#include <vector>
int main()
{
std::vector<std::string>strVec{"Only", "for", "testing", "purpose"};
std::size_t res = std::transform_reduce(
std::execution::par,
strVec.begin(), strVec.end(),
0,
[](std::size_t a, std::size_t b) {return a + b; },
[](std::string s) {return s.size(); }
); // the value of res is 21
}
|
_Ty _Val{_Reduce_op(_Transform_op(*_Chunk._First), _Transform_op(*++_Next))};
|
Per [transform.reduce], IIUC list-initialization shouldn't be used here. We should only use implicit conversion (in other words, copy-initialization).
There're some other parallel numeric algorithms direct-initializing _Ty variables from the results of the binary operations. Perhaps they are also buggy.
(Despite being contrived, it's possible to make T(bin_op(l, r)) ill-formed while T t = bin_op(l, r); being well-formed.)
Command-line test case
Godbolt link
Describe the bug
The following program doesn't compile with MSVC STL due to narrowing conversion in list-initialization.
(originally discovered by mq白 (@Mq-b) in Mq-b/Loser-HomeWork@099c66a)
STL/stl/inc/execution
Line 4235 in f392449
Per [transform.reduce], IIUC list-initialization shouldn't be used here. We should only use implicit conversion (in other words, copy-initialization).
There're some other parallel numeric algorithms direct-initializing
_Tyvariables from the results of the binary operations. Perhaps they are also buggy.(Despite being contrived, it's possible to make
T(bin_op(l, r))ill-formed whileT t = bin_op(l, r);being well-formed.)Command-line test case
Godbolt link