Author: mydeveloperday
Date: 2019-11-16T14:37:47Z
New Revision: 5987cc1bb5d5eb624135e76a6b3ade1aef94caf7

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

LOG: [clang-format] fix regression in middle pointer alignment

Summary:
a75f8d98d7ac introduced a regression with Middle pointer alignment,
which this patch fixes.

Reviewers: MyDeveloperDay, klimek, sammccall

Reviewed By: MyDeveloperDay, sammccall

Subscribers: cfe-commits, merge_guards_bot

Patch by: Typz

Tags: #clang

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

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 dcdc6e6e3364..9fe7fdc9ce93 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2694,7 +2694,7 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
     // Space between the type and the *
     // operator void*(), operator char*(), operator Foo*() dependant
     // on PointerAlignment style.
-    return (Style.PointerAlignment == FormatStyle::PAS_Right);
+    return (Style.PointerAlignment != FormatStyle::PAS_Left);
   const auto SpaceRequiredForArrayInitializerLSquare =
       [](const FormatToken &LSquareTok, const FormatStyle &Style) {
         return Style.SpacesInContainerLiterals ||

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e900936a1e67..d89ad44e4577 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14970,6 +14970,28 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("Foo::operator&&(void&&);", Style);
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+
+  Style.PointerAlignment = FormatStyle::PAS_Middle;
+  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("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("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);
 }
 
 } // namespace


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to