[clang-format] [PR52595] clang-format does not recognize rvalue references to array

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.

Reviewed By: curdeius

Differential Revision: https://reviews.llvm.org/D114519
This commit is contained in:
mydeveloperday 2021-11-25 11:04:17 +00:00
parent 57470abc41
commit c94667a810
2 changed files with 10 additions and 4 deletions

View File

@ -317,7 +317,7 @@ private:
// void (^ObjCBlock)(void); // void (^ObjCBlock)(void);
bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression; bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
bool ProbablyFunctionType = bool ProbablyFunctionType =
CurrentToken->isOneOf(tok::star, tok::amp, tok::caret); CurrentToken->isOneOf(tok::star, tok::amp, tok::ampamp, tok::caret);
bool HasMultipleLines = false; bool HasMultipleLines = false;
bool HasMultipleParametersOnALine = false; bool HasMultipleParametersOnALine = false;
bool MightBeObjCForRangeLoop = bool MightBeObjCForRangeLoop =

View File

@ -9670,6 +9670,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("void f() { a->operator()(a & a); }"); verifyFormat("void f() { a->operator()(a & a); }");
verifyFormat("void f() { a.operator()(*a & *a); }"); verifyFormat("void f() { a.operator()(*a & *a); }");
verifyFormat("void f() { a->operator()(*a * *a); }"); verifyFormat("void f() { a->operator()(*a * *a); }");
verifyFormat("int operator()(T (&&)[N]) { return 1; }");
verifyFormat("int operator()(T (&)[N]) { return 0; }");
} }
TEST_F(FormatTest, UnderstandsAttributes) { TEST_F(FormatTest, UnderstandsAttributes) {
@ -21876,6 +21879,7 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("Foo::operator&(void &);", Style); verifyFormat("Foo::operator&(void &);", Style);
verifyFormat("Foo::operator&();", Style); verifyFormat("Foo::operator&();", Style);
verifyFormat("operator&(int (&)(), class Foo);", Style); verifyFormat("operator&(int (&)(), class Foo);", Style);
verifyFormat("operator&&(int (&)(), class Foo);", Style);
verifyFormat("Foo::operator&&();", Style); verifyFormat("Foo::operator&&();", Style);
verifyFormat("Foo::operator**();", Style); verifyFormat("Foo::operator**();", Style);
@ -21884,7 +21888,7 @@ TEST_F(FormatTest, OperatorSpacing) {
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("operator&&(int(&&)(), class Foo);", Style); verifyFormat("operator&&(int (&&)(), class Foo);", Style);
verifyFormat("operator const nsTArrayRight<E> &()", Style); verifyFormat("operator const nsTArrayRight<E> &()", Style);
verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()", verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()",
Style); Style);
@ -21935,6 +21939,8 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("Foo::operator&(void&);", Style); verifyFormat("Foo::operator&(void&);", Style);
verifyFormat("Foo::operator&();", Style); verifyFormat("Foo::operator&();", Style);
verifyFormat("operator&(int (&)(), class Foo);", Style); verifyFormat("operator&(int (&)(), class Foo);", Style);
verifyFormat("operator&(int (&&)(), class Foo);", Style);
verifyFormat("operator&&(int (&&)(), class Foo);", Style);
verifyFormat("Foo::operator&&();", Style); verifyFormat("Foo::operator&&();", Style);
verifyFormat("Foo::operator void&&();", Style); verifyFormat("Foo::operator void&&();", Style);
@ -21945,7 +21951,7 @@ TEST_F(FormatTest, OperatorSpacing) {
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("operator&&(int(&&)(), class Foo);", Style); verifyFormat("operator&&(int (&&)(), class Foo);", Style);
verifyFormat("operator const nsTArrayLeft<E>&()", Style); verifyFormat("operator const nsTArrayLeft<E>&()", Style);
verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()", verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()",
Style); Style);
@ -21986,7 +21992,7 @@ TEST_F(FormatTest, OperatorSpacing) {
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("operator&&(int(&&)(), class Foo);", Style); verifyFormat("operator&&(int (&&)(), class Foo);", Style);
} }
TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) { TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) {