You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<execution>
#include<numeric>
#include<string>
#include<vector>intmain()
{
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
}
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.)
Describe the bug
The following program doesn't compile with MSVC STL due to narrowing conversion in list-initialization.
(originally discovered by @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
_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 whileT t = bin_op(l, r);
being well-formed.)Command-line test case
Godbolt link
The text was updated successfully, but these errors were encountered: