]> granicus.if.org Git - clang/commitdiff
clang-format: No space in "<::" in C++11 mode.
authorDaniel Jasper <djasper@google.com>
Sat, 12 Oct 2013 05:16:06 +0000 (05:16 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 12 Oct 2013 05:16:06 +0000 (05:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192524 91177308-0d34-0410-b5e6-96231b3b80d8

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

index aac9fffb01e3edf906f1bcf4e70834f0af3ae468..7e92a705cad9b1fa9417895a0be37c98241ea25f 100644 (file)
@@ -1012,10 +1012,14 @@ private:
             ++CountBoundToType;
         }
 
-        if (Tok->Type == TT_TemplateCloser &&
-            Tok->Previous->Type == TT_TemplateCloser &&
-            Tok->WhitespaceRange.getBegin() == Tok->WhitespaceRange.getEnd())
-          HasCpp03IncompatibleFormat = true;
+        if (Tok->WhitespaceRange.getBegin() == Tok->WhitespaceRange.getEnd()) {
+          if (Tok->is(tok::coloncolon) &&
+              Tok->Previous->Type == TT_TemplateOpener)
+            HasCpp03IncompatibleFormat = true;
+          if (Tok->Type == TT_TemplateCloser &&
+              Tok->Previous->Type == TT_TemplateCloser)
+            HasCpp03IncompatibleFormat = true;
+        }
 
         if (Tok->PackingKind == PPK_BinPacked)
           HasBinPackedFunction = true;
index e1ffc25f6331a616583d0ab368506d095c1a13a1..4d95ecfe4f9f95dbacd273e80749f9106ea549db 100644 (file)
@@ -1231,8 +1231,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   if (Left.is(tok::coloncolon))
     return false;
   if (Right.is(tok::coloncolon))
-    return !Left.isOneOf(tok::identifier, tok::greater, tok::l_paren,
-                         tok::r_paren);
+    return (Left.is(tok::less) && Style.Standard == FormatStyle::LS_Cpp03) ||
+           !Left.isOneOf(tok::identifier, tok::greater, tok::l_paren,
+                         tok::r_paren, tok::less);
   if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
     return false;
   if (Right.is(tok::ellipsis))
index f80dc6fc34be45c45335dd2643f7293239519ffd..5fea8e781eb1b35fdf7001fcdf08fa384196cd26 100644 (file)
@@ -3711,8 +3711,14 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
   verifyGoogleFormat("A<A<int> > a;");
   verifyGoogleFormat("A<A<A<int> > > a;");
   verifyGoogleFormat("A<A<A<A<int> > > > a;");
+  verifyGoogleFormat("A<::A<int>> a;");
+  verifyGoogleFormat("A<::A> a;");
+  verifyGoogleFormat("A< ::A> a;");
+  verifyGoogleFormat("A< ::A<int> > a;");
   EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A> >> a;", getGoogleStyle()));
   EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A>> > a;", getGoogleStyle()));
+  EXPECT_EQ("A<::A<int>> a;", format("A< ::A<int>> a;", getGoogleStyle()));
+  EXPECT_EQ("A<::A<int>> a;", format("A<::A<int> > a;", getGoogleStyle()));
 
   verifyFormat("test >> a >> b;");
   verifyFormat("test << a >> b;");