From c47d7f1237b022eabbbdcebf77506e8a81aa54bd Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 1 Jul 2013 09:47:25 +0000 Subject: [PATCH] Don't add an extra space before ellipsis after pointers. Before (for styles where the pointer binds to the type): template void Foo(Ts... ts) {} template void Foo(Ts* ... ts) {} After: template void Foo(Ts... ts) {} template void Foo(Ts*... ts) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185321 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 4 ++-- unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 7cbacd9042..f7cea124a8 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1065,6 +1065,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return !Left.isOneOf(tok::identifier, tok::greater, tok::l_paren); if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less)) return false; + if (Right.is(tok::ellipsis)) + return false; if (Right.Type == TT_PointerOrReference) return Left.Tok.isLiteral() || ((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) && @@ -1110,8 +1112,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Left.isOneOf(tok::identifier, tok::greater, tok::r_square) && Right.is(tok::l_brace) && Right.getNextNoneComment()) return false; - if (Right.is(tok::ellipsis)) - return false; if (Left.is(tok::period) || Right.is(tok::period)) return false; if (Left.Type == TT_BlockComment && Left.TokenText.endswith("=*/")) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 25e1d49f08..5bdc1b949d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3284,6 +3284,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { TEST_F(FormatTest, UnderstandsEllipsis) { verifyFormat("int printf(const char *fmt, ...);"); verifyFormat("template void Foo(Ts... ts) { Foo(ts...); }"); + verifyFormat("template void Foo(Ts *... ts) {}"); + + FormatStyle PointersLeft = getLLVMStyle(); + PointersLeft.PointerBindsToType = true; + verifyFormat("template void Foo(Ts*... ts) {}", PointersLeft); } TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) { -- 2.50.1