[clang-format] Space between attribute closing parenthesis and qualified type colon.

Fixes https://github.com/llvm/llvm-project/issues/35711.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D117894
This commit is contained in:
Marek Kurdej 2022-01-24 17:57:21 +01:00
parent 74db5c8c95
commit 50999e82e8
2 changed files with 5 additions and 0 deletions

View File

@ -3339,6 +3339,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Left.is(tok::ellipsis) && Right.is(tok::identifier) &&
Line.First->is(Keywords.kw_import))
return false;
// Space in __attribute__((attr)) ::type.
if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon))
return true;
if (Left.is(tok::kw_operator))
return Right.is(tok::coloncolon);

View File

@ -10028,6 +10028,7 @@ TEST_F(FormatTest, UnderstandsAttributes) {
verifyFormat("SomeType s __attribute__((unused)) (InitValue);");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n"
"aaaaaaaaaaaaaaaaaaaaaaa(int i);");
verifyFormat("__attribute__((nodebug)) ::qualified_type f();");
FormatStyle AfterType = getLLVMStyle();
AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
verifyFormat("__attribute__((nodebug)) void\n"
@ -10131,6 +10132,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) {
verifyFormat("class [[nodiscard]] f {\npublic:\n f() {}\n}");
verifyFormat("class [[deprecated(\"so sorry\")]] f {\npublic:\n f() {}\n}");
verifyFormat("class [[gnu::unused]] f {\npublic:\n f() {}\n}");
verifyFormat("[[nodiscard]] ::qualified_type f();");
// Make sure we do not mistake attributes for array subscripts.
verifyFormat("int a() {}\n"