]> granicus.if.org Git - clang/commitdiff
Fix parsing of fold-expressions within a cast expression. We parse the
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 11 Nov 2014 03:28:50 +0000 (03:28 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 11 Nov 2014 03:28:50 +0000 (03:28 +0000)
parenthesized expression a bit differently in this case, just in case the
commas have special meaning.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221661 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/SemaTemplate/cxx1z-fold-expressions.cpp

index 6913de9fa1900d7c3f4ab7960bbf1de1ad5a36fd..f4eef81175540e15f23a6582ae7d9d1735a3e0a0 100644 (file)
@@ -2203,24 +2203,30 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
       Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
       return ExprError();
     }
+  } else if (Tok.is(tok::ellipsis) &&
+             isFoldOperator(NextToken().getKind())) {
+    return ParseFoldExpression(ExprResult(), T);
   } else if (isTypeCast) {
     // Parse the expression-list.
     InMessageExpressionRAIIObject InMessage(*this, false);
-    
+
     ExprVector ArgExprs;
     CommaLocsTy CommaLocs;
 
     if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) {
+      // FIXME: If we ever support comma expressions as operands to
+      // fold-expressions, we'll need to allow multiple ArgExprs here.
+      if (ArgExprs.size() == 1 && isFoldOperator(Tok.getKind()) &&
+          NextToken().is(tok::ellipsis))
+        return ParseFoldExpression(Result, T);
+
       ExprType = SimpleExpr;
       Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
                                           ArgExprs);
     }
-  } else if (Tok.is(tok::ellipsis) &&
-             isFoldOperator(NextToken().getKind())) {
-    return ParseFoldExpression(ExprResult(), T);
   } else {
     InMessageExpressionRAIIObject InMessage(*this, false);
-    
+
     Result = ParseExpression(MaybeTypeCast);
     ExprType = SimpleExpr;
 
index 3934f011a3590fd73d4bdfb12547a0c7b7068a94..8bb79113fa9d27f2caca34e80cd426d115fdb352 100644 (file)
@@ -55,10 +55,9 @@ template<int ...N> void empty_with_base() {
   extern int k;
   (k = ... = N); // expected-warning{{unused}}
 
-  // FIXME: We misparse these. The first one looks a lot loke a declaration;
-  // it's not clear what's happening in the second one.
   void (k = ... = N); // expected-error {{expected ')'}} expected-note {{to match}}
-  (void) (k = ... = N); // expected-error {{expected ')'}} expected-note {{to match}}
+  void ((k = ... = N));
+  (void) (k = ... = N);
 }
 template void empty_with_base<>(); // expected-note {{in instantiation of}}
 template void empty_with_base<1>();