[PATCH] D49848: Parse a possible trailing postsfix expression suffix after a fold expression
Nicolas Lesser via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 26 05:36:13 PDT 2018
Rakete1111 created this revision.
Rakete1111 added a reviewer: rsmith.
This patch allows the parsing of a postfix expression involving a fold expression, which is legal as a fold-expression is a primary-expression.
See also https://llvm.org/pr38282
Repository:
rC Clang
https://reviews.llvm.org/D49848
Files:
lib/Parse/ParseExpr.cpp
test/Parser/cxx1z-fold-expressions.cpp
Index: test/Parser/cxx1z-fold-expressions.cpp
===================================================================
--- test/Parser/cxx1z-fold-expressions.cpp
+++ test/Parser/cxx1z-fold-expressions.cpp
@@ -60,3 +60,21 @@
}
static_assert(nestedFoldOperator<3, 1>() == 1);
+
+// A fold-expression is a primary-expression.
+template <typename T, typename... Ts>
+constexpr auto castSum(Ts... Args) {
+ return (T)(Args + ...).Value; // expected-error{{member reference base type 'int' is not a structure or union}}
+}
+
+void prim() {
+ castSum<int>(1, 2);
+ // expected-note at -1{{in instantiation of function template specialization}}
+
+ struct Number {
+ int Value;
+ constexpr Number operator+(Number Rhs) const { return {Rhs.Value + Value}; }
+ };
+
+ static_assert(castSum<long>(Number{1}, Number{2}) == 3);
+}
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -2514,7 +2514,10 @@
}
} else if (Tok.is(tok::ellipsis) &&
isFoldOperator(NextToken().getKind())) {
- return ParseFoldExpression(ExprResult(), T);
+ Result = ParseFoldExpression(ExprResult(), T);
+ if (!Result.isInvalid())
+ Result = ParsePostfixExpressionSuffix(Result.get());
+ return Result;
} else if (isTypeCast) {
// Parse the expression-list.
InMessageExpressionRAIIObject InMessage(*this, false);
@@ -2526,8 +2529,12 @@
// 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(ArgExprs[0], T);
+ NextToken().is(tok::ellipsis)) {
+ Result = ParseFoldExpression(ArgExprs[0], T);
+ if (!Result.isInvalid())
+ Result = ParsePostfixExpressionSuffix(Result.get());
+ return Result;
+ }
ExprType = SimpleExpr;
Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
@@ -2544,8 +2551,12 @@
}
ExprType = SimpleExpr;
- if (isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis))
- return ParseFoldExpression(Result, T);
+ if (isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) {
+ Result = ParseFoldExpression(Result, T);
+ if (!Result.isInvalid())
+ Result = ParsePostfixExpressionSuffix(Result.get());
+ return Result;
+ }
// Don't build a paren expression unless we actually match a ')'.
if (!Result.isInvalid() && Tok.is(tok::r_paren))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49848.157465.patch
Type: text/x-patch
Size: 2652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180726/66f807bc/attachment.bin>
More information about the cfe-commits
mailing list