From 78a4e619e775b0dbaa10c9feaea0adf1d3dfe507 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sat, 12 Oct 2013 05:16:06 +0000 Subject: [PATCH] clang-format: No space in "<::" in C++11 mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192524 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 12 ++++++++---- lib/Format/TokenAnnotator.cpp | 5 +++-- unittests/Format/FormatTest.cpp | 6 ++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index aac9fffb01..7e92a705ca 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index e1ffc25f63..4d95ecfe4f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f80dc6fc34..5fea8e781e 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3711,8 +3711,14 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { verifyGoogleFormat("A > a;"); verifyGoogleFormat("A > > a;"); verifyGoogleFormat("A > > > a;"); + verifyGoogleFormat("A<::A> a;"); + verifyGoogleFormat("A<::A> a;"); + verifyGoogleFormat("A< ::A> a;"); + verifyGoogleFormat("A< ::A > a;"); EXPECT_EQ("A>> a;", format("A >> a;", getGoogleStyle())); EXPECT_EQ("A>> a;", format("A> > a;", getGoogleStyle())); + EXPECT_EQ("A<::A> a;", format("A< ::A> a;", getGoogleStyle())); + EXPECT_EQ("A<::A> a;", format("A<::A > a;", getGoogleStyle())); verifyFormat("test >> a >> b;"); verifyFormat("test << a >> b;"); -- 2.40.0