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] Check request: modernize-use-ctad-to-construct-heterogenous-containers #121295

Open
denzor200 opened this issue Dec 29, 2024 · 0 comments
Labels
check-request Request for a new check in clang-tidy clang-tidy

Comments

@denzor200
Copy link

C++17 suggests us a way to invoke templated class constructor without explicit template arguments specification.
Without that feature we had to use special wrappers like std::make_pair and std::make_tuple, so we don't want them anymore(except the case when std::reference_wrapper passed).

extern int a;
extern int b;
auto t1 = std::make_tuple(a, b);           // INCORRECT
auto t2 = std::tuple{a, b};                // OK
auto p1 = std::make_pair(a, b);            // INCORRECT
auto p2 = std::pair{a, b};                 // OK
auto t3 = std::make_tuple(std::ref(a), b); // OK because of `std::reference_wrapper`
auto p3 = std::make_pair(std::cref(a), b); // OK the same reason

Bear in mind that this check should not work with generic types, because it's impossible to know is that types are reference wrappers:

template<typename T>
void process(T a, int b) {
    auto p1 = std::make_pair(a, b);                   // OK
    auto p2 = std::make_pair(static_cast<int>(a), b); // INCORRECT, should be changed to `std::pair{static_cast<int>(a), b}`
}
@EugeneZelenko EugeneZelenko added the check-request Request for a new check in clang-tidy label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
check-request Request for a new check in clang-tidy clang-tidy
Projects
None yet
Development

No branches or pull requests

2 participants