From: Eli Friedman Date: Tue, 13 Aug 2013 23:38:34 +0000 (+0000) Subject: Fix Altivec vector literal parser hack for C++11. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fce06cd52a8f4714524baa13b544ead9fd298a4;p=clang Fix Altivec vector literal parser hack for C++11. It doesn't make any sense to accept "..." in the argument to a C-style cast, so use a separate expression list parsing routine which rejects it. PR16874. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188330 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 606c67e427..f9995e6162 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1267,6 +1267,12 @@ private: ArrayRef Args) = 0, Expr *Data = 0); + /// ParseSimpleExpressionList - A simple comma-separated list of expressions, + /// used for misc language extensions. + bool ParseSimpleExpressionList(SmallVectorImpl &Exprs, + SmallVectorImpl &CommaLocs); + + /// ParenParseOption - Control what ParseParenExpression will parse. enum ParenParseOption { SimpleExpr, // Only parse '(' expression ')' diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index c093b0c3f5..07d8ba5a90 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1371,7 +1371,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { CommaLocsTy ExecConfigCommaLocs; SourceLocation OpenLoc = ConsumeToken(); - if (ParseExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) { + if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) { LHS = ExprError(); } @@ -2141,7 +2141,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, ExprVector ArgExprs; CommaLocsTy CommaLocs; - if (!ParseExpressionList(ArgExprs, CommaLocs)) { + if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) { ExprType = SimpleExpr; Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(), ArgExprs); @@ -2370,6 +2370,32 @@ bool Parser::ParseExpressionList(SmallVectorImpl &Exprs, } } +/// ParseSimpleExpressionList - A simple comma-separated list of expressions, +/// used for misc language extensions. +/// +/// \verbatim +/// simple-expression-list: +/// assignment-expression +/// simple-expression-list , assignment-expression +/// \endverbatim +bool +Parser::ParseSimpleExpressionList(SmallVectorImpl &Exprs, + SmallVectorImpl &CommaLocs) { + while (1) { + ExprResult Expr = ParseAssignmentExpression(); + if (Expr.isInvalid()) + return true; + + Exprs.push_back(Expr.release()); + + if (Tok.isNot(tok::comma)) + return false; + + // Move to the next argument, remember where the comma was. + CommaLocs.push_back(ConsumeToken()); + } +} + /// ParseBlockId - Parse a block-id, which roughly looks like int (int x). /// /// \verbatim diff --git a/test/Parser/cxx-altivec.cpp b/test/Parser/cxx-altivec.cpp index 9b2b1af22f..be00e494fd 100644 --- a/test/Parser/cxx-altivec.cpp +++ b/test/Parser/cxx-altivec.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s __vector char vv_c; __vector signed char vv_sc; @@ -168,3 +168,7 @@ public: __vector float xyzw; __vector float abcd; } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}} + +template void PR16874() { + (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +}