OSDN Git Service

[clang-format] Parse __attribute((foo)) as a pointer qualifier
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fri, 28 Aug 2020 10:03:00 +0000 (11:03 +0100)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fri, 28 Aug 2020 10:31:47 +0000 (11:31 +0100)
Before: void f() { MACRO(A * __attribute((foo)) a); }
After:  void f() { MACRO(A *__attribute((foo)) a); }

Also check that the __attribute__ alias is handled.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D86711

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index dfcd92d..e5c0a7c 100644 (file)
@@ -1892,7 +1892,7 @@ private:
     if (!NextToken ||
         NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const,
                            tok::kw_restrict, tok::kw_volatile,
-                           tok::kw_noexcept) ||
+                           tok::kw___attribute, tok::kw_noexcept) ||
         (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
       return TT_PointerOrReference;
 
index 95fdbec..1234462 100644 (file)
@@ -8059,6 +8059,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO(A *volatile a);");
   verifyIndependentOfContext("MACRO(A *__volatile a);");
   verifyIndependentOfContext("MACRO(A *__volatile__ a);");
+  verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);");
+  verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);");
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   // FIXME: Is there a way to make this work?