[clang] 73b62f8 - Fix parsing of comma fold-expressions as the operand of a C-style cast.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 4 17:08:18 PDT 2022


Author: Richard Smith
Date: 2022-08-04T17:08:08-07:00
New Revision: 73b62f813550b602f189afc3a60b0b39ae89f16d

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

LOG: Fix parsing of comma fold-expressions as the operand of a C-style cast.

Added: 
    

Modified: 
    clang/lib/Parse/ParseExpr.cpp
    clang/test/Parser/cxx1z-fold-expressions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index a6a946d7f31b1..52d4938b1ecfc 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3469,7 +3469,9 @@ Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
 
     Exprs.push_back(Expr.get());
 
-    if (Tok.isNot(tok::comma))
+    // We might be parsing the LHS of a fold-expression. If we reached the fold
+    // operator, stop.
+    if (Tok.isNot(tok::comma) || NextToken().is(tok::ellipsis))
       return false;
 
     // Move to the next argument, remember where the comma was.

diff  --git a/clang/test/Parser/cxx1z-fold-expressions.cpp b/clang/test/Parser/cxx1z-fold-expressions.cpp
index 93ee6f20ffc6d..ac27111697737 100644
--- a/clang/test/Parser/cxx1z-fold-expressions.cpp
+++ b/clang/test/Parser/cxx1z-fold-expressions.cpp
@@ -41,7 +41,13 @@ template<typename ...T> void as_operand_of_cast(int a, T ...t) {
     (int)(t + ... + undeclared_junk) + // expected-error {{undeclared}}
     (int)(... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}}
     (int)(undeclared_junk + ...) + // expected-error {{undeclared}}
-    (int)(a + ...); // expected-error {{does not contain any unexpanded}}
+    (int)(a + ...) + // expected-error {{does not contain any unexpanded}}
+    (int)(a, ...) + // expected-error {{does not contain any unexpanded}}
+    (int)(..., a) + // expected-error {{does not contain any unexpanded}}
+    (int)(a, ..., undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}}
+    (int)(t, ...) +
+    (int)(..., t) +
+    (int)(t, ..., a);
 }
 
 // fold-operator can be '>' or '>>'.


        


More information about the cfe-commits mailing list