]> granicus.if.org Git - clang/commitdiff
Don't format sizeof/alignof as function types.
authorDaniel Jasper <djasper@google.com>
Tue, 14 May 2013 08:34:47 +0000 (08:34 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 14 May 2013 08:34:47 +0000 (08:34 +0000)
Before: A<sizeof (*x)> a;
After:  A<sizeof(*x)> a;

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

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

index 29eaaa8b581bb46b70577071fc4ce7f04f67f78b..0f91b110339bd685cbeff6fd4c128a53f280ca79 100644 (file)
@@ -173,7 +173,9 @@ private:
       }
       if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
         return false;
-      if (CurrentToken->Parent->Type == TT_PointerOrReference &&
+      if (Left->Parent &&
+          !Left->Parent->isOneOf(tok::kw_sizeof, tok::kw_alignof) &&
+          CurrentToken->Parent->Type == TT_PointerOrReference &&
           CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon))
         Left->DefinesFunctionType = true;
       updateParameterCount(Left, CurrentToken);
index b2ae3d2560d1fb8339c79c2ec744dd8e642539e0..b2393f578b763e53515add32c5f3a8c3d221b053 100644 (file)
@@ -2790,6 +2790,10 @@ TEST_F(FormatTest, FormatsFunctionTypes) {
 
   verifyGoogleFormat("A<void*(int*, SomeType*)>;");
   verifyGoogleFormat("void* (*a)(int);");
+
+  // Other constructs can look like function types:
+  verifyFormat("A<sizeof(*x)> a;");
+  verifyFormat("A<alignof(*x)> a;");
 }
 
 TEST_F(FormatTest, BreaksLongDeclarations) {