aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/QualifierAlignmentFixer.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2025-06-25 00:01:06 -0700
committerGitHub <noreply@github.com>2025-06-25 00:01:06 -0700
commit01b288fe6a1e627954329198ed5641f2bf55ee8d (patch)
treeb5e76e2d1fac9db800b73d3de72338fad6d26474 /clang/lib/Format/QualifierAlignmentFixer.cpp
parent34bfa4e7898ce2338d805c4065bf0d33681d20c0 (diff)
downloadllvm-01b288fe6a1e627954329198ed5641f2bf55ee8d.zip
llvm-01b288fe6a1e627954329198ed5641f2bf55ee8d.tar.gz
llvm-01b288fe6a1e627954329198ed5641f2bf55ee8d.tar.bz2
[clang-format] Improve QualifierAlignment in guessing macros (#145468)
Fixes #145388
Diffstat (limited to 'clang/lib/Format/QualifierAlignmentFixer.cpp')
-rw-r--r--clang/lib/Format/QualifierAlignmentFixer.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 8e55d33..b0dda65 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -635,15 +635,26 @@ bool isConfiguredQualifierOrType(const FormatToken *Tok,
// If a token is an identifier and it's upper case, it could
// be a macro and hence we need to be able to ignore it.
bool isPossibleMacro(const FormatToken *Tok) {
- if (!Tok)
- return false;
+ assert(Tok);
if (Tok->isNot(tok::identifier))
return false;
- if (Tok->TokenText.upper() == Tok->TokenText.str()) {
- // T,K,U,V likely could be template arguments
- return Tok->TokenText.size() != 1;
- }
- return false;
+
+ const auto Text = Tok->TokenText;
+ assert(Text.size() > 0);
+
+ // T,K,U,V likely could be template arguments
+ if (Text.size() == 1)
+ return false;
+
+ // It's unlikely that qualified names are object-like macros.
+ const auto *Prev = Tok->getPreviousNonComment();
+ if (Prev && Prev->is(tok::coloncolon))
+ return false;
+ const auto *Next = Tok->getNextNonComment();
+ if (Next && Next->is(tok::coloncolon))
+ return false;
+
+ return Text == Text.upper();
}
} // namespace format