[cfe-commits] r169594 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Fri Dec 7 01:52:16 PST 2012


Author: djasper
Date: Fri Dec  7 03:52:15 2012
New Revision: 169594

URL: http://llvm.org/viewvc/llvm-project?rev=169594&view=rev
Log:
Small tweaks to clang-format.

Now not joining keywords with '::' and not putting a space between
a pointer pointer.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=169594&r1=169593&r2=169594&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Dec  7 03:52:15 2012
@@ -696,16 +696,20 @@
       return false;
     if (Left.is(tok::less) || Right.is(tok::greater) || Right.is(tok::less))
       return false;
+    if (Right.is(tok::amp) || Right.is(tok::star))
+      return Left.isLiteral() ||
+          (Left.isNot(tok::star) && Left.isNot(tok::amp) &&
+           !Style.PointerAndReferenceBindToType);
     if (Left.is(tok::amp) || Left.is(tok::star))
       return Right.isLiteral() || Style.PointerAndReferenceBindToType;
     if (Right.is(tok::star) && Left.is(tok::l_paren))
       return false;
-    if (Right.is(tok::amp) || Right.is(tok::star))
-      return Left.isLiteral() || !Style.PointerAndReferenceBindToType;
     if (Left.is(tok::l_square) || Right.is(tok::l_square) ||
         Right.is(tok::r_square))
       return false;
-    if (Left.is(tok::coloncolon) || Right.is(tok::coloncolon))
+    if (Left.is(tok::coloncolon) ||
+        (Right.is(tok::coloncolon) &&
+         (Left.is(tok::identifier) || Left.is(tok::greater))))
       return false;
     if (Left.is(tok::period) || Right.is(tok::period))
       return false;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=169594&r1=169593&r2=169594&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Dec  7 03:52:15 2012
@@ -277,6 +277,8 @@
 TEST_F(FormatTest, FormatsDerivedClass) {
   verifyFormat("class A : public B {\n"
                "};");
+  verifyFormat("class A : public ::B {\n"
+               "};");
 }
 
 TEST_F(FormatTest, FormatsEnum) {
@@ -474,6 +476,9 @@
   verifyFormat("int a = *b;");
   verifyFormat("int a = *b * c;");
   verifyFormat("int a = b * *c;");
+  verifyFormat("int main(int argc, char **argv) {\n}");
+
+  verifyGoogleFormat("int main(int argc, char** argv) {\n}");
 }
 
 TEST_F(FormatTest, LineStartsWithSpecialCharacter) {





More information about the cfe-commits mailing list