Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::exclusive_scan narrows to type of initial value #61575

Open
upsj opened this issue Mar 21, 2023 · 1 comment
Open

std::exclusive_scan narrows to type of initial value #61575

upsj opened this issue Mar 21, 2023 · 1 comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@upsj
Copy link
Contributor

upsj commented Mar 21, 2023

#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 to 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. Related to NVIDIA/cccl#836

https://godbolt.org/z/zMf5M9hGK

@upsj upsj added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 21, 2023
@jwakely
Copy link
Contributor

jwakely commented Mar 21, 2023

This is the subject of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0571r2.html#intermediate_unordered which proposes to make it explicit that the summation is done with the type of the init parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants