[clang] c82243d - [clang-format] : Fix additional pointer alignment for overloaded operators

via cfe-commits cfe-commits at lists.llvm.org
Wed May 13 10:36:00 PDT 2020


Author: mydeveloperday
Date: 2020-05-13T18:33:57+01:00
New Revision: c82243d0675bad130d22a9301d3dc1e7cfb05c2f

URL: https://github.com/llvm/llvm-project/commit/c82243d0675bad130d22a9301d3dc1e7cfb05c2f
DIFF: https://github.com/llvm/llvm-project/commit/c82243d0675bad130d22a9301d3dc1e7cfb05c2f.diff

LOG: [clang-format] : Fix additional pointer alignment for overloaded operators

Summary:
Follow on from {D78879} to handle the more obscure to prevent spaces between operators

```
operator void *&();
operator void *&&();
operator void &*();
operator void &&*();
```

Reviewers: sylvestre.ledru, sammccall, krasimir, Abpostelnicu

Reviewed By: sammccall, Abpostelnicu

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79201

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 76d1d4b60202..043859a2f5c0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2818,7 +2818,7 @@ 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))
+  if (Left.is(tok::star) && Right.isOneOf(tok::star, tok::amp, tok::ampamp))
     return false;
   if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
     const FormatToken *Previous = &Left;

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 430423fbf941..1308487bb9f1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -15760,6 +15760,8 @@ TEST_F(FormatTest, OperatorSpacing) {
   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()(void *);", Style);
   verifyFormat("Foo::operator*(void *);", Style);
   verifyFormat("Foo::operator*();", Style);
@@ -15773,6 +15775,10 @@ TEST_F(FormatTest, OperatorSpacing) {
   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);
@@ -15796,12 +15802,15 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("operator const FooRight<Object> &()", Style);
   verifyFormat("operator const FooRight<Object> *()", 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 void*&();", Style);
   verifyFormat("Foo::operator/*comment*/ void*();", Style);
   verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style);
   verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style);
@@ -15812,10 +15821,13 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("Foo::operator<Foo>*();", Style);
   verifyFormat("Foo::operator<int>**();", Style);
   verifyFormat("Foo::operator<Foo>**();", 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);
@@ -15844,6 +15856,8 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("operator const FooLeft<Object>&()", Style);
   verifyFormat("operator const FooLeft<Object>*()", 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);


        


More information about the cfe-commits mailing list