llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.31k stars 12.11k forks source link

[clang-tidy] `bugprone-throw-keyword-missing` false negatives from `hasAncestor` skipping too much #115540

Open 5chmidti opened 2 weeks ago

5chmidti commented 2 weeks ago

The matcher is using hasAncestor and could be skipping many different issues, simply because they have an ancestor node (e.g., VarDecl) but that node is not closely related to the construct expression itself.

struct RegularException {
    RegularException(int);
};
void foo() {
    const auto var = []() {
        RegularException{0};  // FN, ignored because of `hasAncestor(varDecl())`
        return 0;
    };
}

struct Bar {
    Bar() : v{0} {
        RegularException{0};  // FN, ignored because of `hasAncestor(cxxConstructorDecl())`
    }
    int v;
};

https://godbolt.org/z/6br6f91vc

llvmbot commented 2 weeks ago

@llvm/issue-subscribers-clang-tidy

Author: Julian Schmidt (5chmidti)

The matcher is using `hasAncestor` and could be skipping many different issues, simply because they have an ancestor node (e.g., `VarDecl`) but that node is not closely related to the construct expression itself. ```c++ struct RegularException { RegularException(int); }; void foo() { const auto var = []() { RegularException{0}; // FN, ignored because of `hasAncestor(varDecl())` return 0; }; } struct Bar { Bar() : v{0} { RegularException{0}; // FN, ignored because of `hasAncestor(cxxConstructorDecl())` } int v; }; ``` https://godbolt.org/z/6br6f91vc