-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!
Description
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)
#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
}Line 4235 in f392449
| _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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!