diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1840,6 +1840,12 @@ T = T->MatchingParen->Previous->Previous; continue; } + } else if (T->is(TT_AttributeSquare)) { + // Handle `x = (foo *[[clang::foo]])&v;`: + if (T->MatchingParen && T->MatchingParen->Previous) { + T = T->MatchingParen->Previous; + continue; + } } else if (T->canBePointerOrReferenceQualifier()) { T = T->Previous; continue; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8068,6 +8068,7 @@ verifyIndependentOfContext("MACRO(A *_Null_unspecified a);"); verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);"); verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);"); + verifyIndependentOfContext("MACRO(A *[[clang::attr]] a);"); verifyIndependentOfContext("MACRO('0' <= c && c <= '9');"); verifyFormat("void f() { f(float{1}, a * a); }"); // FIXME: Is there a way to make this work? @@ -8137,14 +8138,16 @@ verifyFormat("x = (foo *_Nullable)*v;"); verifyFormat("x = (foo *_Null_unspecified)*v;"); verifyFormat("x = (foo *_Nonnull)*v;"); + verifyFormat("x = (foo *[[clang::attr]])*v;"); // Check that we handle multiple trailing qualifiers and skip them all to // determine that the expression is a cast to a pointer type. FormatStyle LongPointerRight = getLLVMStyleWithColumns(999); FormatStyle LongPointerLeft = getLLVMStyleWithColumns(999); LongPointerLeft.PointerAlignment = FormatStyle::PAS_Left; - StringRef AllQualifiers = "const volatile restrict __attribute__((foo)) " - "_Nonnull _Null_unspecified _Nonnull"; + StringRef AllQualifiers = + "const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified " + "_Nonnull [[clang::attr]]"; verifyFormat(("x = (foo *" + AllQualifiers + ")*v;").str(), LongPointerRight); verifyFormat(("x = (foo* " + AllQualifiers + ")*v;").str(), LongPointerLeft);