<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/115540>115540</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] `bugprone-throw-keyword-missing` false negatives from `hasAncestor` skipping too much
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy,
            false-negative
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          5chmidti
      </td>
    </tr>
</table>

<pre>
    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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VMGSozYQ_Rpx6bJLCIPNgcN4HI45pFK5C6kBZYVESQ07ztenZGOvszOV27pURojWe_1eSy1jNINDbFh5ZuUlkwuNPjSlGiejyWSd19fmzxFhkqRGDGAiLNG4AVjFRxnfnMJIPrCKg3QalF-shg4hfjPznOIm6a6gTd9jQEdgYlwwMvEO0UyzvUKHSi4RgUa8wihXBOlAbrDgvEZg4oT7YZ82sYr_JcMFlWUVZ6KGbiGgUdI90kRwnkBZH9FeIaCVhBrIJ3hQ3kUKiyLAjzlgjMY7MBTR9nvGL4y_bf8Vvw_FxDmN2-q29Q8cFivDbx8KZ0oA7LgFfPrExMk4YqJmxRbCjpfnfPVGQ-89E6ck5AcMwD1TkAt5WGUAVlzgXqCvgtPvE_XxzO9kAEy0TLTQ_p4MNIPzAfXTdt__XElxWjeHb1xpVPy_bAFpCQ74U0tafNWW5i-Gbtadk5TXzM8yPAQVb7BuSf9iderj4_1xEPz_CH1qSC_GEaxflvF5WF4Fj0RzZMXbPbnB685b2vswMNH-w0RbdaHq63xVmW4KXRe1zLDJj0XO6-pYHLKxKU-FEv3x1HVlrqoeUZV4qPv-2GmpDuKYmUZwcchzfhI8F3mxl6e60LzktcxlVeQFO3CcpLF7a9cpcWe3u9fkeVkeeGZlhzbe7r0Qyko37MjoKxOCiXcmRC9txJ3DQZJZMS2Xlyw0CWzXLUNkB25NpPgDngzZWyN5QSsvqQDdMszBO9zRGPz33Te8fvdB7yYTUytJvePGBg-2CH3w0xct5tlVyHuYFjVmS7DNT24bGpdur_zERJuS2x67Ofi_URET7aMJtZsXayP-DQAA__8zj4Qt">