MyDeveloperDay created this revision. MyDeveloperDay added reviewers: sylvestre.ledru, mitchell-stellar, sammccall. MyDeveloperDay added projects: clang, clang-format. Herald added a subscriber: cfe-commits. MyDeveloperDay updated this revision to Diff 260171. MyDeveloperDay added a comment. MyDeveloperDay edited the summary of this revision. MyDeveloperDay edited the summary of this revision.
More test cases 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: [clang-format] [PR36294] AlwaysBreakAfterReturnType works incorrectly for some operator functions <https://reviews.llvm.org/D69573> We may need to gather some more use cases. Pre the changes in D69573 <https://reviews.llvm.org/D69573> the output was: class UniquePtrGetterAddRefs { operator void **() { return reinterpret_cast<void **>(&mPtrStorage); } } class ReturnToGlobal { operator LocalRef<Object> *() { return &objRef; } } In the last windows snapshot (11.0.0.2263) (Feb 2020) the output was: class UniquePtrGetterAddRefs { operator void * *() { return reinterpret_cast<void **>(&mPtrStorage); } } class ReturnToGlobal { operator LocalRef<Object> *() { return &objRef; } } post fix the out is: class UniquePtrGetterAddRefs { operator void **() { return reinterpret_cast<void **>(&mPtrStorage); } } class ReturnToGlobal { operator LocalRef<Object>*() { return &objRef; } } Is the removal of the space between the <Object> and the* what you expect? https://reviews.llvm.org/D78879 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -6279,7 +6279,15 @@ "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 void **() {}\n", Style); verifyFormat("constexpr auto\n" "operator()() const -> reference {}\n" @@ -15628,9 +15636,15 @@ 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<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); @@ -15650,12 +15664,17 @@ Style.PointerAlignment = FormatStyle::PAS_Left; 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("operator*(int (*)(), class Foo);", Style); verifyFormat("Foo::operator&();", Style); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2281,6 +2281,10 @@ Next = Next->Next; continue; } + if (Next->is(TT_TemplateOpener) && Next->MatchingParen) { + Next = Next->MatchingParen; + continue; + } break; } @@ -2810,6 +2814,10 @@ 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.is(tok::star) && Left.is(TT_TemplateCloser)) + return false; if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) { const FormatToken *Previous = &Left; while (Previous && !Previous->is(tok::kw_operator)) {
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -6279,7 +6279,15 @@ "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 void **() {}\n", Style); verifyFormat("constexpr auto\n" "operator()() const -> reference {}\n" @@ -15628,9 +15636,15 @@ 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<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); @@ -15650,12 +15664,17 @@ Style.PointerAlignment = FormatStyle::PAS_Left; 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("operator*(int (*)(), class Foo);", Style); verifyFormat("Foo::operator&();", Style); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2281,6 +2281,10 @@ Next = Next->Next; continue; } + if (Next->is(TT_TemplateOpener) && Next->MatchingParen) { + Next = Next->MatchingParen; + continue; + } break; } @@ -2810,6 +2814,10 @@ 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.is(tok::star) && Left.is(TT_TemplateCloser)) + return false; if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) { const FormatToken *Previous = &Left; while (Previous && !Previous->is(tok::kw_operator)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits