* operators.def: Add *_FOLD_EXPR.
* cp-tree.h (FOLD_EXPR_P): Parenthesize.
* mangle.c (write_expression): Handle fold-expressions.
* pt.c (tsubst_unary_left_fold, tsubst_binary_left_fold)
(tsubst_unary_right_fold, tsubst_binary_right_fold): Handle
partial instantiation.
From-SVN: r238390
2016-07-15 Jason Merrill <jason@redhat.com>
+ PR c++/71711
+ * operators.def: Add *_FOLD_EXPR.
+ * cp-tree.h (FOLD_EXPR_P): Parenthesize.
+ * mangle.c (write_expression): Handle fold-expressions.
+ * pt.c (tsubst_unary_left_fold, tsubst_binary_left_fold)
+ (tsubst_unary_right_fold, tsubst_binary_right_fold): Handle
+ partial instantiation.
+
PR c++/71814
* mangle.c (write_expression): Handle sizeof... an argument pack.
TREE_CHECK2 (NODE, BINARY_LEFT_FOLD_EXPR, BINARY_RIGHT_FOLD_EXPR)
/* True if NODE is UNARY_FOLD_EXPR or a BINARY_FOLD_EXPR */
-#define FOLD_EXPR_P(NODE) \
- TREE_CODE (NODE) == UNARY_LEFT_FOLD_EXPR \
- || TREE_CODE (NODE) == UNARY_RIGHT_FOLD_EXPR \
- || TREE_CODE (NODE) == BINARY_LEFT_FOLD_EXPR \
- || TREE_CODE (NODE) == BINARY_RIGHT_FOLD_EXPR
+#define FOLD_EXPR_P(NODE) \
+ (TREE_CODE (NODE) == UNARY_LEFT_FOLD_EXPR \
+ || TREE_CODE (NODE) == UNARY_RIGHT_FOLD_EXPR \
+ || TREE_CODE (NODE) == BINARY_LEFT_FOLD_EXPR \
+ || TREE_CODE (NODE) == BINARY_RIGHT_FOLD_EXPR)
/* True when NODE is a fold over a compound assignment operator. */
#define FOLD_EXPR_MODIFY_P(NODE) \
"cannot be mangled");
continue;
}
+ else if (FOLD_EXPR_P (expr))
+ {
+ /* The first 'operand' of a fold-expression is the operator
+ that it folds over. */
+ if (i == 0)
+ {
+ int fcode = TREE_INT_CST_LOW (operand);
+ write_string (operator_name_info[fcode].mangled_name);
+ continue;
+ }
+ else if (code == BINARY_LEFT_FOLD_EXPR)
+ {
+ /* The order of operands of the binary left and right
+ folds is the same, but we want to mangle them in
+ lexical order, i.e. non-pack first. */
+ if (i == 1)
+ operand = FOLD_EXPR_INIT (expr);
+ else
+ operand = FOLD_EXPR_PACK (expr);
+ }
+ if (PACK_EXPANSION_P (operand))
+ operand = PACK_EXPANSION_PATTERN (operand);
+ }
write_expression (operand);
}
}
/* Variadic templates extension. */
DEF_SIMPLE_OPERATOR ("...", EXPR_PACK_EXPANSION, "sp", 1)
+DEF_SIMPLE_OPERATOR ("... +", UNARY_LEFT_FOLD_EXPR, "fl", 2)
+DEF_SIMPLE_OPERATOR ("+ ...", UNARY_RIGHT_FOLD_EXPR, "fr", 2)
+DEF_SIMPLE_OPERATOR ("+ ... +", BINARY_LEFT_FOLD_EXPR, "fL", 3)
+DEF_SIMPLE_OPERATOR ("+ ... +", BINARY_RIGHT_FOLD_EXPR, "fR", 3)
tree pack = tsubst_fold_expr_pack (t, args, complain, in_decl);
if (pack == error_mark_node)
return error_mark_node;
+ if (PACK_EXPANSION_P (pack))
+ {
+ tree r = copy_node (t);
+ FOLD_EXPR_PACK (r) = pack;
+ return r;
+ }
if (TREE_VEC_LENGTH (pack) == 0)
return expand_empty_fold (t, complain);
else
if (init == error_mark_node)
return error_mark_node;
+ if (PACK_EXPANSION_P (pack))
+ {
+ tree r = copy_node (t);
+ FOLD_EXPR_PACK (r) = pack;
+ FOLD_EXPR_INIT (r) = init;
+ return r;
+ }
+
tree vec = make_tree_vec (TREE_VEC_LENGTH (pack) + 1);
TREE_VEC_ELT (vec, 0) = init;
for (int i = 0; i < TREE_VEC_LENGTH (pack); ++i)
tree pack = tsubst_fold_expr_pack (t, args, complain, in_decl);
if (pack == error_mark_node)
return error_mark_node;
+ if (PACK_EXPANSION_P (pack))
+ {
+ tree r = copy_node (t);
+ FOLD_EXPR_PACK (r) = pack;
+ return r;
+ }
if (TREE_VEC_LENGTH (pack) == 0)
return expand_empty_fold (t, complain);
else
if (init == error_mark_node)
return error_mark_node;
+ if (PACK_EXPANSION_P (pack))
+ {
+ tree r = copy_node (t);
+ FOLD_EXPR_PACK (r) = pack;
+ FOLD_EXPR_INIT (r) = init;
+ return r;
+ }
+
int n = TREE_VEC_LENGTH (pack);
tree vec = make_tree_vec (n + 1);
for (int i = 0; i < n; ++i)
--- /dev/null
+// PR c++/71711
+// { dg-options -std=c++1z }
+
+template < int > struct A {};
+template < int ... N > void unary_left (A < (... + N) >);
+template < int ... N > void unary_right (A < (N + ...) >);
+template < int ... N > void binary_left (A < (42 + ... + N) >);
+template < int ... N > void binary_right (A < (N + ... + 42) >);
+
+void bar ()
+{
+ // { dg-final { scan-assembler "_Z10unary_leftIJLi1ELi2ELi3EEEv1AIXflplT_EE" } }
+ unary_left < 1, 2, 3 > ({});
+ // { dg-final { scan-assembler "_Z11unary_rightIJLi1ELi2ELi3EEEv1AIXfrplT_EE" } }
+ unary_right < 1, 2, 3 > ({});
+ // { dg-final { scan-assembler "_Z11binary_leftIJLi1ELi2ELi3EEEv1AIXfLplLi42ET_EE" } }
+ binary_left < 1, 2, 3 > ({});
+ // { dg-final { scan-assembler "_Z12binary_rightIJLi1ELi2ELi3EEEv1AIXfRplT_Li42EEE" } }
+ binary_right < 1, 2, 3 > ({});
+}