re PR c++/59012 (alignas does not support parameter pack expansions)
PR c++/59012 * parser.c (cp_parser_std_attribute_list): Handle attribute expansion. (cp_parser_std_attribute_spec): Handle alignas pack expansion. * decl2.c (is_late_template_attribute): An attribute exp is dependent. * pt.c (make_pack_expansion): Allow TREE_LIST for attribute expansion. (apply_late_template_attributes): Handle attribute pack expansion. From-SVN: r222902
This commit is contained in:
parent
d87333bcc8
commit
90f11cf950
|
@ -1,3 +1,12 @@
|
||||||
|
2015-05-07 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
PR c++/59012
|
||||||
|
* parser.c (cp_parser_std_attribute_list): Handle attribute expansion.
|
||||||
|
(cp_parser_std_attribute_spec): Handle alignas pack expansion.
|
||||||
|
* decl2.c (is_late_template_attribute): An attribute exp is dependent.
|
||||||
|
* pt.c (make_pack_expansion): Allow TREE_LIST for attribute expansion.
|
||||||
|
(apply_late_template_attributes): Handle attribute pack expansion.
|
||||||
|
|
||||||
2015-05-07 Marek Polacek <polacek@redhat.com>
|
2015-05-07 Marek Polacek <polacek@redhat.com>
|
||||||
|
|
||||||
PR c/65179
|
PR c/65179
|
||||||
|
|
|
@ -1175,6 +1175,10 @@ is_late_template_attribute (tree attr, tree decl)
|
||||||
&& is_attribute_p ("omp declare simd", name))
|
&& is_attribute_p ("omp declare simd", name))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
/* An attribute pack is clearly dependent. */
|
||||||
|
if (args && PACK_EXPANSION_P (args))
|
||||||
|
return true;
|
||||||
|
|
||||||
/* If any of the arguments are dependent expressions, we can't evaluate
|
/* If any of the arguments are dependent expressions, we can't evaluate
|
||||||
the attribute until instantiation time. */
|
the attribute until instantiation time. */
|
||||||
for (arg = args; arg; arg = TREE_CHAIN (arg))
|
for (arg = args; arg; arg = TREE_CHAIN (arg))
|
||||||
|
|
|
@ -22486,6 +22486,13 @@ cp_parser_std_attribute_list (cp_parser *parser)
|
||||||
attributes = attribute;
|
attributes = attribute;
|
||||||
}
|
}
|
||||||
token = cp_lexer_peek_token (parser->lexer);
|
token = cp_lexer_peek_token (parser->lexer);
|
||||||
|
if (token->type == CPP_ELLIPSIS)
|
||||||
|
{
|
||||||
|
cp_lexer_consume_token (parser->lexer);
|
||||||
|
TREE_VALUE (attribute)
|
||||||
|
= make_pack_expansion (TREE_VALUE (attribute));
|
||||||
|
token = cp_lexer_peek_token (parser->lexer);
|
||||||
|
}
|
||||||
if (token->type != CPP_COMMA)
|
if (token->type != CPP_COMMA)
|
||||||
break;
|
break;
|
||||||
cp_lexer_consume_token (parser->lexer);
|
cp_lexer_consume_token (parser->lexer);
|
||||||
|
@ -22564,20 +22571,27 @@ cp_parser_std_attribute_spec (cp_parser *parser)
|
||||||
return alignas_expr;
|
return alignas_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alignas_expr = cxx_alignas_expr (alignas_expr);
|
||||||
|
alignas_expr = build_tree_list (NULL_TREE, alignas_expr);
|
||||||
|
|
||||||
|
if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
|
||||||
|
{
|
||||||
|
cp_lexer_consume_token (parser->lexer);
|
||||||
|
alignas_expr = make_pack_expansion (alignas_expr);
|
||||||
|
}
|
||||||
|
|
||||||
if (cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN) == NULL)
|
if (cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN) == NULL)
|
||||||
{
|
{
|
||||||
cp_parser_error (parser, "expected %<)%>");
|
cp_parser_error (parser, "expected %<)%>");
|
||||||
return error_mark_node;
|
return error_mark_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
alignas_expr = cxx_alignas_expr (alignas_expr);
|
|
||||||
|
|
||||||
/* Build the C++-11 representation of an 'aligned'
|
/* Build the C++-11 representation of an 'aligned'
|
||||||
attribute. */
|
attribute. */
|
||||||
attributes =
|
attributes =
|
||||||
build_tree_list (build_tree_list (get_identifier ("gnu"),
|
build_tree_list (build_tree_list (get_identifier ("gnu"),
|
||||||
get_identifier ("aligned")),
|
get_identifier ("aligned")),
|
||||||
build_tree_list (NULL_TREE, alignas_expr));
|
alignas_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
|
|
19
gcc/cp/pt.c
19
gcc/cp/pt.c
|
@ -3338,9 +3338,9 @@ make_pack_expansion (tree arg)
|
||||||
if (!arg || arg == error_mark_node)
|
if (!arg || arg == error_mark_node)
|
||||||
return arg;
|
return arg;
|
||||||
|
|
||||||
if (TREE_CODE (arg) == TREE_LIST)
|
if (TREE_CODE (arg) == TREE_LIST && TREE_PURPOSE (arg))
|
||||||
{
|
{
|
||||||
/* The only time we will see a TREE_LIST here is for a base
|
/* A TREE_LIST with a non-null TREE_PURPOSE is for a base
|
||||||
class initializer. In this case, the TREE_PURPOSE will be a
|
class initializer. In this case, the TREE_PURPOSE will be a
|
||||||
_TYPE node (representing the base class expansion we're
|
_TYPE node (representing the base class expansion we're
|
||||||
initializing) and the TREE_VALUE will be a TREE_LIST
|
initializing) and the TREE_VALUE will be a TREE_LIST
|
||||||
|
@ -9012,6 +9012,21 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags,
|
||||||
= tree_cons (NULL_TREE, TREE_VALUE (TREE_VALUE (t)),
|
= tree_cons (NULL_TREE, TREE_VALUE (TREE_VALUE (t)),
|
||||||
chain);
|
chain);
|
||||||
}
|
}
|
||||||
|
else if (TREE_VALUE (t) && PACK_EXPANSION_P (TREE_VALUE (t)))
|
||||||
|
{
|
||||||
|
/* An attribute pack expansion. */
|
||||||
|
tree purp = TREE_PURPOSE (t);
|
||||||
|
tree pack = (tsubst_pack_expansion
|
||||||
|
(TREE_VALUE (t), args, complain, in_decl));
|
||||||
|
int len = TREE_VEC_LENGTH (pack);
|
||||||
|
for (int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
tree elt = TREE_VEC_ELT (pack, i);
|
||||||
|
*q = build_tree_list (purp, elt);
|
||||||
|
q = &TREE_CHAIN (*q);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
TREE_VALUE (t)
|
TREE_VALUE (t)
|
||||||
= tsubst_expr (TREE_VALUE (t), args, complain, in_decl,
|
= tsubst_expr (TREE_VALUE (t), args, complain, in_decl,
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
// PR c++/59012
|
||||||
|
// { dg-do compile { target c++11 } }
|
||||||
|
// { dg-final { scan-assembler "align 8" { target x86_64-*-*-gnu } } }
|
||||||
|
|
||||||
|
template <class... T>
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
alignas(T...) char t;
|
||||||
|
};
|
||||||
|
|
||||||
|
A<int,double> a;
|
||||||
|
|
||||||
|
template <class... T>
|
||||||
|
struct A2
|
||||||
|
{
|
||||||
|
[[gnu::aligned (alignof (T))...]] char t;
|
||||||
|
};
|
||||||
|
|
||||||
|
A2<int,double> a2;
|
Loading…
Reference in New Issue