Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2844,6 +2844,11 @@ Left.Previous && !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon, tok::l_square)); + // Ensure right pointer alignement with ellipsis e.g. int *...P + if (Left.is(tok::ellipsis) && Left.Previous && + Left.Previous->isOneOf(tok::star, tok::amp, tok::ampamp)) + return Style.PointerAlignment != FormatStyle::PAS_Right; + if (Right.is(tok::star) && Left.is(tok::l_paren)) return false; if (Left.is(tok::star) && Right.isOneOf(tok::star, tok::amp, tok::ampamp)) Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -5325,7 +5325,7 @@ verifyFormat("template S(Ts...) -> S;"); verifyFormat( "template \n" - "array(T &&... t) -> array, sizeof...(T)>;"); + "array(T &&...t) -> array, sizeof...(T)>;"); verifyFormat("template A() -> Afoo<3>())>;"); verifyFormat("template A() -> A>)>;"); verifyFormat("template A() -> Afoo<1>)>;"); @@ -8179,13 +8179,20 @@ } TEST_F(FormatTest, UnderstandsEllipsis) { + FormatStyle Style = getLLVMStyle(); verifyFormat("int printf(const char *fmt, ...);"); verifyFormat("template void Foo(Ts... ts) { Foo(ts...); }"); - verifyFormat("template void Foo(Ts *... ts) {}"); + verifyFormat("template void Foo(Ts *...ts) {}"); + + verifyFormat("template a;", Style); + + Style.PointerAlignment = FormatStyle::PAS_Left; + verifyFormat("template void Foo(Ts*... ts) {}", Style); + + verifyFormat("template a;", Style); - FormatStyle PointersLeft = getLLVMStyle(); - PointersLeft.PointerAlignment = FormatStyle::PAS_Left; - verifyFormat("template void Foo(Ts*... ts) {}", PointersLeft); + Style.PointerAlignment = FormatStyle::PAS_Middle; + verifyFormat("template a;", Style); } TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {