MyDeveloperDay created this revision. MyDeveloperDay added reviewers: HazardyKnusperkeks, curdeius, owenpan. MyDeveloperDay added projects: clang, clang-format. MyDeveloperDay requested review of this revision.
https://bugs.llvm.org/show_bug.cgi?id=52595 missing space between `T (&&)` but not between `T(&` due to && being incorrectly thought of as `UnaryOperator` rather than `PointerOrReference` int operator()(T (&)[N]) { return 0; } int operator()(T(&&)[N]) { return 1; } Existing Unit tests are changed because actually I think they are originally incorrect, and are inconsistent with the (&) cases that are 4 or 5 lines above them. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D114519 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 @@ -9659,6 +9659,11 @@ verifyFormat("void f() { a->operator()(*a * *a); }"); } +TEST_F(FormatTest, AmpAmpOperator) { + verifyFormat("int operator()(T (&&)[N]) { return 1; }"); + verifyFormat("int operator()(T (&)[N]) { return 0; }"); +} + TEST_F(FormatTest, UnderstandsAttributes) { verifyFormat("SomeType s __attribute__((unused)) (InitValue);"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n" @@ -21871,7 +21876,7 @@ verifyFormat("Foo::operator()(void &&);", Style); verifyFormat("Foo::operator&&(void &&);", Style); verifyFormat("Foo::operator&&();", Style); - verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator&&(int (&&)(), class Foo);", Style); verifyFormat("operator const nsTArrayRight<E> &()", Style); verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()", Style); @@ -21932,7 +21937,7 @@ verifyFormat("Foo::operator()(void&&);", Style); verifyFormat("Foo::operator&&(void&&);", Style); verifyFormat("Foo::operator&&();", Style); - verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator&&(int (&&)(), class Foo);", Style); verifyFormat("operator const nsTArrayLeft<E>&()", Style); verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()", Style); @@ -21973,7 +21978,7 @@ verifyFormat("Foo::operator()(void &&);", Style); verifyFormat("Foo::operator&&(void &&);", Style); verifyFormat("Foo::operator&&();", Style); - verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator&&(int (&&)(), class Foo);", Style); } TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -317,7 +317,7 @@ // void (^ObjCBlock)(void); bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression; bool ProbablyFunctionType = - CurrentToken->isOneOf(tok::star, tok::amp, tok::caret); + CurrentToken->isOneOf(tok::star, tok::amp, tok::ampamp, tok::caret); bool HasMultipleLines = false; bool HasMultipleParametersOnALine = false; bool MightBeObjCForRangeLoop =
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9659,6 +9659,11 @@ verifyFormat("void f() { a->operator()(*a * *a); }"); } +TEST_F(FormatTest, AmpAmpOperator) { + verifyFormat("int operator()(T (&&)[N]) { return 1; }"); + verifyFormat("int operator()(T (&)[N]) { return 0; }"); +} + TEST_F(FormatTest, UnderstandsAttributes) { verifyFormat("SomeType s __attribute__((unused)) (InitValue);"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n" @@ -21871,7 +21876,7 @@ verifyFormat("Foo::operator()(void &&);", Style); verifyFormat("Foo::operator&&(void &&);", Style); verifyFormat("Foo::operator&&();", Style); - verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator&&(int (&&)(), class Foo);", Style); verifyFormat("operator const nsTArrayRight<E> &()", Style); verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()", Style); @@ -21932,7 +21937,7 @@ verifyFormat("Foo::operator()(void&&);", Style); verifyFormat("Foo::operator&&(void&&);", Style); verifyFormat("Foo::operator&&();", Style); - verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator&&(int (&&)(), class Foo);", Style); verifyFormat("operator const nsTArrayLeft<E>&()", Style); verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()", Style); @@ -21973,7 +21978,7 @@ verifyFormat("Foo::operator()(void &&);", Style); verifyFormat("Foo::operator&&(void &&);", Style); verifyFormat("Foo::operator&&();", Style); - verifyFormat("operator&&(int(&&)(), class Foo);", Style); + verifyFormat("operator&&(int (&&)(), class Foo);", Style); } TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -317,7 +317,7 @@ // void (^ObjCBlock)(void); bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression; bool ProbablyFunctionType = - CurrentToken->isOneOf(tok::star, tok::amp, tok::caret); + CurrentToken->isOneOf(tok::star, tok::amp, tok::ampamp, tok::caret); bool HasMultipleLines = false; bool HasMultipleParametersOnALine = false; bool MightBeObjCForRangeLoop =
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits