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: use std::addressof in generic code for objects of user-defined types #121172

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

Comments

@denzor200
Copy link

Because operator& may be overloaded, generic libraries use std::addressof to obtain addresses of objects of user-defined types.

template<typename T>
void process_0(T& a, int& b, int& c) {
    process_a(&a);                     // INCORRECT
    process_b(&b);                     // OK
    process_c(std::addressof(c));      // OK but redundant
}

template<typename T>
void process_1(T& a, int& b, int& c) {
    process_a(std::addressof(a));       // OK
    process_b(&b);                      // OK
    process_c(std::addressof(c));       // OK but redundant
}


void process_notemplate(int& a, int& b, int& c) {
    process_a(&a);                      // OK
    process_b(&b);                      // OK
    process_c(std::addressof(c));       // OK but redundant
}

template<typename T>
void process_pointers(T* a, std::unique_ptr<T>& b, T* c) {
    process_pointer_to_pointer(&a);                // OK
    process_pointer_to_unique_pointer(&b);         // OK
    process_pointer_to_pointer(std::addressof(c)); // OK but redundant
}
@EugeneZelenko EugeneZelenko added the check-request Request for a new check in clang-tidy label Dec 27, 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