[clang] [clang-format] Handle C++ Core Guidelines suppression tags (PR #86458)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 24 16:16:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->86451.
---
Full diff: https://github.com/llvm/llvm-project/pull/86458.diff
2 Files Affected:
- (modified) clang/lib/Format/TokenAnnotator.cpp (+4)
- (modified) clang/unittests/Format/FormatTest.cpp (+1)
``````````diff
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 03005384a6f667..2f9ff43b9fa5bc 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);");
``````````
</details>
https://github.com/llvm/llvm-project/pull/86458
More information about the cfe-commits
mailing list