re PR c++/79653 (ICE on invalid c++ code in cp_check_const_attributes in cp/decl2...
authorMarek Polacek <polacek@redhat.com>
Wed, 22 Feb 2017 19:31:49 +0000 (19:31 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 22 Feb 2017 19:31:49 +0000 (19:31 +0000)
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

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/alignas10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/alignas9.C [new file with mode: 0644]

index 42c6a52..38b60bc 100644 (file)
@@ -1,3 +1,11 @@
+2017-02-22  Marek Polacek  <polacek@redhat.com>
+
+       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  <jason@redhat.com>
 
        PR c++/50308 - wrong deprecated warning with ADL
index 3992516..e20257c 100644 (file)
@@ -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 %<)%>");
index 38a01e1..5b0f62d 100644 (file)
@@ -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;
index 395620c..628529b 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79653
+       * g++.dg/cpp0x/alignas10.C: New test.
+       * g++.dg/cpp0x/alignas9.C: New test.
+
 2017-02-22  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..164994e
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/79653
+// { dg-do compile { target c++11 } }
+
+template <typename... A> struct outer {
+  template <typename... B> struct alignas(alignof(A) * alignof(B)...) inner {}; // { dg-error "mismatched argument pack lengths" }
+};
+outer<int>::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 (file)
index 0000000..98fe707
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/79653
+// { dg-do compile { target c++11 } }
+
+template <typename... T>
+struct A { alignas(int...) char c; }; // { dg-error "no argument packs|expected" }
+A<int, double> a;