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 <vector>
#include <numeric>
#include <iostream>
#include <limits>
#include <cstdint>

int main() {
        std::vector<std::int64_t> 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.

Reply via email to