Skip to content

[clang-tidy] Check request: bugprone-unreached-function-overload #143329

@denzor200

Description

@denzor200
template<typename T>
void foo(T x) { std::cout << "Template: " << x << "\n"; }

int main() {
    foo(42);      // OK: `Template: 42`
    foo("hello"); // BAD: `Template: hello` (`const char*: hello` expected)
}

// defined after it's being used
void foo(const char* s) { std::cout << "const char*: " << s << "\n"; }

Possible fix is to declare foo(const char* s) before main function.
Another fix is to move foo(const char* s) definition before main function.

The idea for this check was inspired by the article by @akrzemi1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions