[clang] e766f87 - [clang-format] Handle C++ Core Guidelines suppression tags (#86458)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 21:23:01 PDT 2024
Author: Owen Pan
Date: 2024-03-27T21:22:57-07:00
New Revision: e766f87b922933d6b1aefcfd24e5111162369e2e
URL: https://github.com/llvm/llvm-project/commit/e766f87b922933d6b1aefcfd24e5111162369e2e
DIFF: https://github.com/llvm/llvm-project/commit/e766f87b922933d6b1aefcfd24e5111162369e2e.diff
LOG: [clang-format] Handle C++ Core Guidelines suppression tags (#86458)
Fixes #86451.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 4c83a7a3a323be..b9144cf55452e2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4827,6 +4827,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
Right.is(TT_TemplateOpener)) {
return true;
}
+ if (Left.is(tok::identifier) && Right.is(tok::numeric_constant) &&
+ Right.TokenText[0] == '.') {
+ return false;
+ }
} else if (Style.isProto()) {
if (Right.is(tok::period) &&
Left.isOneOf(Keywords.kw_optional, Keywords.kw_required,
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d1e977dfa66af5..33dec7dae319f0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12075,6 +12075,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) {
verifyFormat("SomeType s [[gnu::unused]] (InitValue);");
verifyFormat("SomeType s [[using gnu: unused]] (InitValue);");
verifyFormat("[[gsl::suppress(\"clang-tidy-check-name\")]] void f() {}");
+ verifyFormat("[[suppress(type.5)]] int uninitialized_on_purpose;");
verifyFormat("void f() [[deprecated(\"so sorry\")]];");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" [[unused]] aaaaaaaaaaaaaaaaaaaaaaa(int i);");
More information about the cfe-commits
mailing list