[clang] 21c18d5 - [Format] Fix incorrect pointer detection

Marek Kurdej via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 4 00:39:28 PDT 2021


Author: Yilong Guo
Date: 2021-06-04T09:39:23+02:00
New Revision: 21c18d5a04316891110cecc2bf37ce51533decba

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

LOG: [Format] Fix incorrect pointer detection

https://llvm.org/PR50429

Before:
    void f() { f(float(1), a *a); }

After:
    void f() { f(float(1), a * a); }

Signed-off-by: Yilong Guo <yilong.guo at intel.com>

Reviewed By: HazardyKnusperkeks, curdeius

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

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 4bd9311ebadd4..d08c991daf43f 100755
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -399,7 +399,7 @@ class AnnotatingParser {
         HasMultipleParametersOnALine = true;
       if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
            CurrentToken->Previous->isSimpleTypeSpecifier()) &&
-          !CurrentToken->is(tok::l_brace))
+          !CurrentToken->isOneOf(tok::l_brace, tok::l_paren))
         Contexts.back().IsExpression = false;
       if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
         MightBeObjCForRangeLoop = false;

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index a2583aecf5a9f..5ea4fcc9ffe36 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8706,6 +8706,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
 
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
+  verifyFormat("void f() { f(float(1), a * a); }");
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");
   verifyFormat("MACRO(A &B);");


        


More information about the cfe-commits mailing list