From: Marek Polacek Date: Wed, 22 Feb 2017 19:31:49 +0000 (+0000) Subject: re PR c++/79653 (ICE on invalid c++ code in cp_check_const_attributes in cp/decl2... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78af14ae0e9fd1b698a1fde2ac43dcc31188e3b1;p=gcc.git re PR c++/79653 (ICE on invalid c++ code in cp_check_const_attributes in cp/decl2.c:1423) PR c++/79653 * parser.c (cp_parser_std_attribute_spec): Don't build the attribute if the alignas expression is erroneous. * pt.c (tsubst_attribute): If tsubst_pack_expansion fails, return error_mark_node. * g++.dg/cpp0x/alignas10.C: New test. * g++.dg/cpp0x/alignas9.C: New test. From-SVN: r245657 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 42c6a52f033..38b60bc695f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2017-02-22 Marek Polacek + + PR c++/79653 + * parser.c (cp_parser_std_attribute_spec): Don't build the attribute + if the alignas expression is erroneous. + * pt.c (tsubst_attribute): If tsubst_pack_expansion fails, return + error_mark_node. + 2017-02-21 Jason Merrill PR c++/50308 - wrong deprecated warning with ADL diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3992516de0e..e20257c5bf9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -24977,12 +24977,17 @@ cp_parser_std_attribute_spec (cp_parser *parser) alignas_expr = cxx_alignas_expr (alignas_expr); alignas_expr = build_tree_list (NULL_TREE, alignas_expr); + /* Handle alignas (pack...). */ if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)) { cp_lexer_consume_token (parser->lexer); alignas_expr = make_pack_expansion (alignas_expr); } + /* Something went wrong, so don't build the attribute. */ + if (alignas_expr == error_mark_node) + return error_mark_node; + if (cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN) == NULL) { cp_parser_error (parser, "expected %<)%>"); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 38a01e168a7..5b0f62d3832 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10012,6 +10012,8 @@ tsubst_attribute (tree t, tree *decl_p, tree args, /* An attribute pack expansion. */ tree purp = TREE_PURPOSE (t); tree pack = tsubst_pack_expansion (val, args, complain, in_decl); + if (pack == error_mark_node) + return error_mark_node; int len = TREE_VEC_LENGTH (pack); tree list = NULL_TREE; tree *q = &list; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 395620c6c54..628529b535c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-02-22 Marek Polacek + + PR c++/79653 + * g++.dg/cpp0x/alignas10.C: New test. + * g++.dg/cpp0x/alignas9.C: New test. + 2017-02-22 Jakub Jelinek PR target/70465 diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas10.C b/gcc/testsuite/g++.dg/cpp0x/alignas10.C new file mode 100644 index 00000000000..164994eb12b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignas10.C @@ -0,0 +1,7 @@ +// PR c++/79653 +// { dg-do compile { target c++11 } } + +template struct outer { + template struct alignas(alignof(A) * alignof(B)...) inner {}; // { dg-error "mismatched argument pack lengths" } +}; +outer::inner<> mismatched_packs; diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas9.C b/gcc/testsuite/g++.dg/cpp0x/alignas9.C new file mode 100644 index 00000000000..98fe7077582 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignas9.C @@ -0,0 +1,6 @@ +// PR c++/79653 +// { dg-do compile { target c++11 } } + +template +struct A { alignas(int...) char c; }; // { dg-error "no argument packs|expected" } +A a;