Skip to content

Commit e766f87

Browse files
authored
[clang-format] Handle C++ Core Guidelines suppression tags (#86458)
Fixes #86451.
1 parent 056b404 commit e766f87

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,6 +4827,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
48274827
Right.is(TT_TemplateOpener)) {
48284828
return true;
48294829
}
4830+
if (Left.is(tok::identifier) && Right.is(tok::numeric_constant) &&
4831+
Right.TokenText[0] == '.') {
4832+
return false;
4833+
}
48304834
} else if (Style.isProto()) {
48314835
if (Right.is(tok::period) &&
48324836
Left.isOneOf(Keywords.kw_optional, Keywords.kw_required,

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12075,6 +12075,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) {
1207512075
verifyFormat("SomeType s [[gnu::unused]] (InitValue);");
1207612076
verifyFormat("SomeType s [[using gnu: unused]] (InitValue);");
1207712077
verifyFormat("[[gsl::suppress(\"clang-tidy-check-name\")]] void f() {}");
12078+
verifyFormat("[[suppress(type.5)]] int uninitialized_on_purpose;");
1207812079
verifyFormat("void f() [[deprecated(\"so sorry\")]];");
1207912080
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
1208012081
" [[unused]] aaaaaaaaaaaaaaaaaaaaaaa(int i);");

0 commit comments

Comments
 (0)