[Bug libstdc++/109229] New: std::exclusive_scan narrows to initial value

2023-03-21 Thread gnu-bugzilla at ribizel dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109229

Bug ID: 109229
   Summary: std::exclusive_scan narrows to initial value
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gnu-bugzilla at ribizel dot de
  Target Milestone: ---

Take the following piece of code:
```
#include 
#include 
#include 
#include 
#include 

int main() {
std::vector vec{1LL << 32, 0};
std::exclusive_scan(vec.begin(), vec.end(), vec.begin(), 0);
std::cout << vec[0] << '\n';
std::cout << vec[1] << '\n';
}
```
I would expect this to output 0 and 1LL<<32, but it outputs 0, 0, because T in
std::exclusive_scan is deduced as int, which is the computational type that
will be used in exclusive_scan. Not sure if this is a library or standard
defect, but I think this is pretty bug-prone otherwise. Other standard library
implementations have the same issue, see
https://github.com/NVIDIA/thrust/issues/1896 and
https://github.com/llvm/llvm-project/issues/61575.

[Bug libstdc++/109229] std::exclusive_scan narrows to initial value

2023-03-21 Thread gnu-bugzilla at ribizel dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109229

--- Comment #2 from Tobias Ribizel  ---
I agree, but that doesn't make it less bug-prone IMO, with the narrowing
conversion happening deep inside the exclusive_scan implementation (-Wnarrowing
doesn't pick it up). Something similar like common_type> would be much safer.