]> granicus.if.org Git - clang/commitdiff
Assume macros to contain declarations.
authorDaniel Jasper <djasper@google.com>
Mon, 13 May 2013 07:14:40 +0000 (07:14 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 May 2013 07:14:40 +0000 (07:14 +0000)
This seems to be the vastly more common case. If we find enough
examples to the contrary, we can make it smarter.

Before: #define MACRO void f(int * a)
After:  #define MACRO void f(int *a)

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

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

index 12031166e234ef9939a871c2188c8bc463b0abae..29eaaa8b581bb46b70577071fc4ce7f04f67f78b 100644 (file)
@@ -591,6 +591,7 @@ private:
       }
     } else if (Current.isOneOf(tok::kw_return, tok::kw_throw) ||
                (Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
+                !Line.InPPDirective &&
                 (!Current.Parent || Current.Parent->isNot(tok::kw_for)))) {
       Contexts.back().IsExpression = true;
     } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
index f694c5b2141487634a65ebc26aec23303f48fd14..9b3fb9cc06da02fc357d42819721525df27a49ef 100644 (file)
@@ -2638,10 +2638,16 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("for (int i = a * a; i < 10; ++i) {\n}");
   verifyFormat("for (int i = 0; i < a * a; ++i) {\n}");
 
+  verifyFormat("#define MACRO     \\\n"
+               "  int *i = a * b; \\\n"
+               "  void f(a *b);",
+               getLLVMStyleWithColumns(19));
+
   verifyIndependentOfContext("A = new SomeType *[Length];");
   verifyIndependentOfContext("A = new SomeType *[Length]();");
   verifyGoogleFormat("A = new SomeType* [Length]();");
   verifyGoogleFormat("A = new SomeType* [Length];");
+
   FormatStyle PointerLeft = getLLVMStyle();
   PointerLeft.PointerBindsToType = true;
   verifyFormat("delete *x;", PointerLeft);