r192524 - clang-format: No space in "<::" in C++11 mode.
Daniel Jasper
djasper at google.com
Fri Oct 11 22:16:07 PDT 2013
Author: djasper
Date: Sat Oct 12 00:16:06 2013
New Revision: 192524
URL: http://llvm.org/viewvc/llvm-project?rev=192524&view=rev
Log:
clang-format: No space in "<::" in C++11 mode.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.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=192524&r1=192523&r2=192524&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sat Oct 12 00:16:06 2013
@@ -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;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=192524&r1=192523&r2=192524&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Oct 12 00:16:06 2013
@@ -1231,8 +1231,9 @@ bool TokenAnnotator::spaceRequiredBetwee
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))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=192524&r1=192523&r2=192524&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Oct 12 00:16:06 2013
@@ -3711,8 +3711,14 @@ TEST_F(FormatTest, UnderstandsTemplatePa
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;");
More information about the cfe-commits
mailing list