[clang-tools-extra] [clang-tidy] fix false positives for bugprone-macro-parentheses in C++ templates (PR #174329)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 5 19:55:20 PST 2026
================
@@ -227,17 +228,26 @@ void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok,
// Cast.
if (Prev.is(tok::l_paren) && Next.is(tok::star) &&
- TI + 2 != MI->tokens_end() && (TI + 2)->is(tok::r_paren))
+ std::next(TI, 2) != MI->tokens_end() &&
+ std::next(TI, 2)->is(tok::r_paren))
continue;
// Assignment/return, i.e. '=x;' or 'return x;'.
if (Prev.isOneOf(tok::equal, tok::kw_return) && Next.is(tok::semi))
continue;
// C++ template parameters.
- if (PP->getLangOpts().CPlusPlus && Prev.isOneOf(tok::comma, tok::less) &&
- Next.isOneOf(tok::comma, tok::greater))
- continue;
+ if (PP->getLangOpts().CPlusPlus && Prev.isOneOf(tok::comma, tok::less)) {
+ const auto *NextIt = std::next(TI);
+ while (NextIt != MI->tokens_end() &&
+ NextIt->isOneOf(tok::star, tok::amp, tok::ampamp, tok::kw_const,
+ tok::kw_volatile))
+ ++NextIt;
----------------
localspook wrote:
Could use an algorithm here
```suggestion
const auto *NextIt = std::find_if_not(std::next(TI), MI->tokens_end(), [] (const Token& T) {
return T.isOneOf(tok::star, tok::amp, tok::ampamp, tok::kw_const,
tok::kw_volatile); });
```
https://github.com/llvm/llvm-project/pull/174329
More information about the cfe-commits
mailing list