]> granicus.if.org Git - clang/commitdiff
clang-format: Understand that "auto" is a type.
authorDaniel Jasper <djasper@google.com>
Thu, 3 Apr 2014 09:00:49 +0000 (09:00 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 3 Apr 2014 09:00:49 +0000 (09:00 +0000)
Before:
  MACRO(auto * a);

After:
  MACRO(auto *a);

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

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

index 709e0b856d4b90b458b6df959d65ee0c409c37a7..0034235c32d023fbe372264cecd0b5ebc0fdc883 100644 (file)
@@ -196,7 +196,7 @@ private:
           !CurrentToken->Next->HasUnescapedNewline &&
           !CurrentToken->Next->isTrailingComment())
         HasMultipleParametersOnALine = true;
-      if (CurrentToken->is(tok::kw_const) ||
+      if (CurrentToken->isOneOf(tok::kw_const, tok::kw_auto) ||
           CurrentToken->isSimpleTypeSpecifier())
         Contexts.back().IsExpression = false;
       if (!consumeToken())
index 62ca9ffcc39d5414b360b41141552cd929ab59e9..5395fd98923f0d31e4b62f17ad94ffdb57ae610b 100644 (file)
@@ -4554,6 +4554,12 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("foo<b && false>();");
   verifyFormat("foo<b & 1>();");
 
+  verifyIndependentOfContext("MACRO(int *i);");
+  verifyIndependentOfContext("MACRO(auto *a);");
+  verifyIndependentOfContext("MACRO(const A *a);");
+  // FIXME: Is there a way to make this work?
+  // verifyIndependentOfContext("MACRO(A *a);");
+
   // FIXME: We cannot handle this case yet; we might be able to figure out that
   // foo<x> d > v; doesn't make sense.
   verifyFormat("foo<a < b && c> d > v;");