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

[clang-tidy] Invalid Fix-it modernize-use-ranges #110593

Open
felix642 opened this issue Sep 30, 2024 · 0 comments
Open

[clang-tidy] Invalid Fix-it modernize-use-ranges #110593

felix642 opened this issue Sep 30, 2024 · 0 comments

Comments

@felix642
Copy link
Contributor

The check modernize-use-ranges will flag the following code :

#include <vector>
#include <algorithm>
#include <iostream>

void foo()
{
    std::vector<int> my_vector = {1, 2, 3, 4, 5};
    auto min_max = std::minmax_element(my_vector.begin(), my_vector.end()); // warning: use a ranges version of this algorithm [modernize-use-ranges]
    std::cout << *min_max.first << " " << *min_max.second << '\n';
}

But the return value of std::minmax_element and std::ranges::minmax_element are not the same. The first one returns a std::pair<ForwardIt, ForwardIt> while the second one returns a minmax_element_result<I>.

This means that applying the proposed Fix-It will break the code.

godbolt: https://godbolt.org/z/3rTW78e8x

I do not think there is a simple way to update the code from std::minmax_element to std::ranges::minmax_element so I would suggest to simply diagnose the problem but let the user fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant