diff options
author | Owen Pan <owenpiano@gmail.com> | 2024-03-27 21:22:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-27 21:22:57 -0700 |
commit | e766f87b922933d6b1aefcfd24e5111162369e2e (patch) | |
tree | 753d4846c083ee40a555b96ce465e8feec504efd | |
parent | 056b4043543cbc9e4ecad183db185bd26324b5b1 (diff) | |
download | llvm-e766f87b922933d6b1aefcfd24e5111162369e2e.zip llvm-e766f87b922933d6b1aefcfd24e5111162369e2e.tar.gz llvm-e766f87b922933d6b1aefcfd24e5111162369e2e.tar.bz2 |
[clang-format] Handle C++ Core Guidelines suppression tags (#86458)
Fixes #86451.
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 4c83a7a..b9144cf 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 d1e977d..33dec7d 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);"); |