Author: mydeveloperday Date: 2020-07-12T18:44:26+01:00 New Revision: 65dc97b79eb1979c54e7e17c411ea5f58f8dcc9c
URL: https://github.com/llvm/llvm-project/commit/65dc97b79eb1979c54e7e17c411ea5f58f8dcc9c DIFF: https://github.com/llvm/llvm-project/commit/65dc97b79eb1979c54e7e17c411ea5f58f8dcc9c.diff LOG: [clang-format] PR46609 clang-format does not obey `PointerAlignment: Right` for ellipsis in declarator for pack Summary: https://bugs.llvm.org/show_bug.cgi?id=46609 Ensure `*...` obey they left/middle/right rules of Pointer alignment Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D83564 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a74015d3b4dc..7f8e35126512 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2844,6 +2844,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ff9a64e81d5b..6ac3ffbffd1c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5325,7 +5325,7 @@ TEST_F(FormatTest, DeductionGuides) { verifyFormat("template <class... Ts> S(Ts...) -> S<Ts...>;"); verifyFormat( "template <class... T>\n" - "array(T &&... t) -> array<std::common_type_t<T...>, sizeof...(T)>;"); + "array(T &&...t) -> array<std::common_type_t<T...>, sizeof...(T)>;"); verifyFormat("template <class T> A() -> A<decltype(p->foo<3>())>;"); verifyFormat("template <class T> A() -> A<decltype(foo<traits<1>>)>;"); verifyFormat("template <class T> A() -> A<sizeof(p->foo<1>)>;"); @@ -8179,13 +8179,20 @@ TEST_F(FormatTest, AttributePenaltyBreaking) { } TEST_F(FormatTest, UnderstandsEllipsis) { + FormatStyle Style = getLLVMStyle(); verifyFormat("int printf(const char *fmt, ...);"); verifyFormat("template <class... Ts> void Foo(Ts... ts) { Foo(ts...); }"); - verifyFormat("template <class... Ts> void Foo(Ts *... ts) {}"); + verifyFormat("template <class... Ts> void Foo(Ts *...ts) {}"); + + verifyFormat("template <int *...PP> a;", Style); + + Style.PointerAlignment = FormatStyle::PAS_Left; + verifyFormat("template <class... Ts> void Foo(Ts*... ts) {}", Style); + + verifyFormat("template <int*... PP> a;", Style); - FormatStyle PointersLeft = getLLVMStyle(); - PointersLeft.PointerAlignment = FormatStyle::PAS_Left; - verifyFormat("template <class... Ts> void Foo(Ts*... ts) {}", PointersLeft); + Style.PointerAlignment = FormatStyle::PAS_Middle; + verifyFormat("template <int *... PP> a;", Style); } TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits