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.

Activity

llvmbot

llvmbot commented on Jun 9, 2025

@llvmbot
Member

@llvm/issue-subscribers-clang-tidy

Author: Denis Mikhailov (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.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @EugeneZelenko@denzor200@llvmbot

        Issue actions

          [clang-tidy] Check request: bugprone-unreached-function-overload · Issue #143329 · llvm/llvm-project