Author: mydeveloperday Date: 2020-04-30T10:55:59+01:00 New Revision: b01dca50085768f1f1a5ad21a685906d48c38816
URL: https://github.com/llvm/llvm-project/commit/b01dca50085768f1f1a5ad21a685906d48c38816 DIFF: https://github.com/llvm/llvm-project/commit/b01dca50085768f1f1a5ad21a685906d48c38816.diff LOG: [clang-format] [PR45357] Fix issue found with operator spacing Summary: This is a tentative fix for https://bugs.llvm.org/show_bug.cgi?id=45357 Spaces seem to be introduced between * and * due to changes brought in for {D69573} Reviewers: sylvestre.ledru, mitchell-stellar, sammccall, Abpostelnicu, krasimir, jbcoe Reviewed By: Abpostelnicu Subscribers: tstellar, hans, Abpostelnicu, cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D78879 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 61386cef990a..439fd0f4d863 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2281,6 +2281,10 @@ static bool isFunctionDeclarationName(const FormatToken &Current, Next = Next->Next; continue; } + if (Next->is(TT_TemplateOpener) && Next->MatchingParen) { + Next = Next->MatchingParen; + continue; + } break; } @@ -2810,6 +2814,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, tok::l_square)); if (Right.is(tok::star) && Left.is(tok::l_paren)) return false; + if (Right.is(tok::star) && Left.is(tok::star)) + return false; if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) { const FormatToken *Previous = &Left; while (Previous && !Previous->is(tok::kw_operator)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 69a2001cd995..1cd12476d788 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6279,7 +6279,17 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "void\n" "A::operator[]() {}\n" "void\n" - "A::operator!() {}\n", + "A::operator!() {}\n" + "void\n" + "A::operator**() {}\n" + "void\n" + "A::operator<Foo> *() {}\n" + "void\n" + "A::operator<Foo> **() {}\n" + "void\n" + "A::operator<Foo> &() {}\n" + "void\n" + "A::operator void **() {}\n", Style); verifyFormat("constexpr auto\n" "operator()() const -> reference {}\n" @@ -6296,6 +6306,10 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "constexpr auto\n" "operator void *() const -> reference {}\n" "constexpr auto\n" + "operator void **() const -> reference {}\n" + "constexpr auto\n" + "operator void *() const -> reference {}\n" + "constexpr auto\n" "operator void &() const -> reference {}\n" "constexpr auto\n" "operator void &&() const -> reference {}\n" @@ -15628,9 +15642,20 @@ TEST_F(FormatTest, OperatorSpacing) { Style.PointerAlignment = FormatStyle::PAS_Right; verifyFormat("Foo::operator*();", Style); verifyFormat("Foo::operator void *();", Style); + verifyFormat("Foo::operator void **();", Style); verifyFormat("Foo::operator()(void *);", Style); verifyFormat("Foo::operator*(void *);", Style); verifyFormat("Foo::operator*();", Style); + verifyFormat("Foo::operator**();", Style); + verifyFormat("Foo::operator&();", Style); + verifyFormat("Foo::operator<int> *();", Style); + verifyFormat("Foo::operator<Foo> *();", Style); + verifyFormat("Foo::operator<int> **();", Style); + verifyFormat("Foo::operator<Foo> **();", Style); + verifyFormat("Foo::operator<int> &();", Style); + verifyFormat("Foo::operator<Foo> &();", Style); + verifyFormat("Foo::operator<int> &&();", Style); + verifyFormat("Foo::operator<Foo> &&();", Style); verifyFormat("operator*(int (*)(), class Foo);", Style); verifyFormat("Foo::operator&();", Style); @@ -15641,21 +15666,39 @@ TEST_F(FormatTest, OperatorSpacing) { verifyFormat("operator&(int (&)(), class Foo);", Style); verifyFormat("Foo::operator&&();", Style); + verifyFormat("Foo::operator**();", Style); verifyFormat("Foo::operator void &&();", Style); verifyFormat("Foo::operator()(void &&);", Style); verifyFormat("Foo::operator&&(void &&);", Style); verifyFormat("Foo::operator&&();", Style); verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator const nsTArrayRight<E> &()", Style); + verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()", + Style); + verifyFormat("operator void **()", Style); + verifyFormat("operator const FooRight<Object> &()", Style); + verifyFormat("operator const FooRight<Object> *()", Style); + verifyFormat("operator const FooRight<Object> **()", Style); Style.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("Foo::operator*();", Style); + verifyFormat("Foo::operator**();", Style); verifyFormat("Foo::operator void*();", Style); + verifyFormat("Foo::operator void**();", Style); verifyFormat("Foo::operator/*comment*/ void*();", Style); verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style); verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style); verifyFormat("Foo::operator()(void*);", Style); verifyFormat("Foo::operator*(void*);", Style); verifyFormat("Foo::operator*();", Style); + verifyFormat("Foo::operator<int>*();", Style); + verifyFormat("Foo::operator<Foo>*();", Style); + verifyFormat("Foo::operator<int>**();", Style); + verifyFormat("Foo::operator<Foo>**();", Style); + verifyFormat("Foo::operator<int>&();", Style); + verifyFormat("Foo::operator<Foo>&();", Style); + verifyFormat("Foo::operator<int>&&();", Style); + verifyFormat("Foo::operator<Foo>&&();", Style); verifyFormat("operator*(int (*)(), class Foo);", Style); verifyFormat("Foo::operator&();", Style); @@ -15677,9 +15720,17 @@ TEST_F(FormatTest, OperatorSpacing) { verifyFormat("Foo::operator&&(void&&);", Style); verifyFormat("Foo::operator&&();", Style); verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator const nsTArrayLeft<E>&()", Style); + verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()", + Style); + verifyFormat("operator void**()", Style); + verifyFormat("operator const FooLeft<Object>&()", Style); + verifyFormat("operator const FooLeft<Object>*()", Style); + verifyFormat("operator const FooLeft<Object>**()", Style); // PR45107 verifyFormat("operator Vector<String>&();", Style); + verifyFormat("operator const Vector<String>&();", Style); verifyFormat("operator foo::Bar*();", Style); verifyFormat("operator const Foo<X>::Bar<Y>*();", Style); verifyFormat("operator/*a*/ const /*b*/ Foo /*c*/<X> /*d*/ ::Bar<Y>*();", _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits