]> granicus.if.org Git - clang/commitdiff
clang-format: Fix __attribute__ being treated as decl name.
authorDaniel Jasper <djasper@google.com>
Mon, 6 Jul 2015 11:30:34 +0000 (11:30 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 6 Jul 2015 11:30:34 +0000 (11:30 +0000)
__attribute__ was treated as the name of a function definition, with the
tokens in parentheses being the parameter list. This formats incorrectly
with AlwaysBreakAfterDefinitionReturnType. Fix it by treating
__attribute__ like decltype.

Patch by Strager Neds, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241439 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0e1f14ad05f2798a2c7232813039c58538892b48..f4b9c4eee9e861ac665bdc02e3fa39324a6116d9 100644 (file)
@@ -505,7 +505,8 @@ private:
       if (Line.MustBeDeclaration && Contexts.size() == 1 &&
           !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
           (!Tok->Previous ||
-           !Tok->Previous->isOneOf(tok::kw_decltype, TT_LeadingJavaAnnotation)))
+           !Tok->Previous->isOneOf(tok::kw_decltype, tok::kw___attribute,
+                                   TT_LeadingJavaAnnotation)))
         Line.MightBeFunctionDecl = true;
       break;
     case tok::l_square:
index dfc88fa8f79d9cc200ab6b4b53de73b0190aa673..19ac54ef4e49900dde490ee7c617d426139197ad 100644 (file)
@@ -5553,6 +5553,11 @@ TEST_F(FormatTest, UnderstandsAttributes) {
   verifyFormat("SomeType s __attribute__((unused)) (InitValue);");
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n"
                "aaaaaaaaaaaaaaaaaaaaaaa(int i);");
+  FormatStyle AfterType = getLLVMStyle();
+  AfterType.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
+  verifyFormat("__attribute__((nodebug)) void\n"
+               "foo() {}\n",
+               AfterType);
 }
 
 TEST_F(FormatTest, UnderstandsEllipsis) {