+2015-11-19 Jason Merrill <jason@redhat.com>
+
+ PR c++/68422
+ * cp-tree.h (PACK_EXPANSION_SIZEOF_P): New.
+ * parser.c (cp_parser_sizeof_pack): Set it.
+ * pt.c (tsubst_copy) [SIZEOF_EXPR]: Likewise.
+ (tsubst_pack_expansion): Improve T... shortcut for expression packs.
+
2015-11-19 Ryan Burn <contact@rnburn.com>
PR c++/68396
DECLTYPE_FOR_INIT_CAPTURE (in DECLTYPE_TYPE)
CONSTRUCTOR_NO_IMPLICIT_ZERO (in CONSTRUCTOR)
TINFO_USED_TEMPLATE_ID (in TEMPLATE_INFO)
+ PACK_EXPANSION_SIZEOF_P (in *_PACK_EXPANSION)
2: IDENTIFIER_OPNAME_P (in IDENTIFIER_NODE)
ICS_THIS_FLAG (in _CONV)
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (in VAR_DECL)
/* True iff this pack expansion is within a function context. */
#define PACK_EXPANSION_LOCAL_P(NODE) TREE_LANG_FLAG_0 (NODE)
+/* True iff this pack expansion is for sizeof.... */
+#define PACK_EXPANSION_SIZEOF_P(NODE) TREE_LANG_FLAG_1 (NODE)
+
/* True iff the wildcard can match a template parameter pack. */
#define WILDCARD_PACK_P(NODE) TREE_LANG_FLAG_0 (NODE)
else if (TREE_CODE (expr) == CONST_DECL)
expr = DECL_INITIAL (expr);
expr = make_pack_expansion (expr);
+ PACK_EXPANSION_SIZEOF_P (expr) = true;
if (paren)
cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
}
}
- /* If the expansion is just T..., return the matching argument pack. */
+ /* If the expansion is just T..., return the matching argument pack, unless
+ we need to call convert_from_reference on all the elements. This is an
+ important optimization; see c++/68422. */
if (!unsubstituted_packs
&& TREE_PURPOSE (packs) == pattern)
{
tree args = ARGUMENT_PACK_ARGS (TREE_VALUE (packs));
+ /* Types need no adjustment, nor does sizeof..., and if we still have
+ some pack expansion args we won't do anything yet. */
if (TREE_CODE (t) == TYPE_PACK_EXPANSION
+ || PACK_EXPANSION_SIZEOF_P (t)
|| pack_expansion_args_count (args))
return args;
+ /* Also optimize expression pack expansions if we can tell that the
+ elements won't have reference type. */
+ tree type = TREE_TYPE (pattern);
+ if (type && TREE_CODE (type) != REFERENCE_TYPE
+ && !PACK_EXPANSION_P (type)
+ && !WILDCARD_TYPE_P (type))
+ return args;
/* Otherwise use the normal path so we get convert_from_reference. */
}
case SIZEOF_EXPR:
if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
{
-
tree expanded, op = TREE_OPERAND (t, 0);
int len = 0;
{
if (TREE_CODE (expanded) == TREE_VEC)
expanded = TREE_VEC_ELT (expanded, len - 1);
+ else
+ PACK_EXPANSION_SIZEOF_P (expanded) = true;
if (TYPE_P (expanded))
return cxx_sizeof_or_alignof_type (expanded, SIZEOF_EXPR,