Skip to content

Commit

Permalink
[clang-format] Handle C++ Core Guidelines suppression tags (#86458)
Browse files Browse the repository at this point in the history
Fixes #86451.
  • Loading branch information
owenca committed Mar 28, 2024
1 parent 056b404 commit e766f87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);");
Expand Down

0 comments on commit e766f87

Please sign in to comment.