re PR c++/79535 (ICE in verify_ctor_sanity, at cp/constexpr.c:2636)
authorMarek Polacek <polacek@redhat.com>
Tue, 21 Feb 2017 20:23:09 +0000 (20:23 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 21 Feb 2017 20:23:09 +0000 (20:23 +0000)
PR c++/79535
* cp-tree.h (maybe_reject_flexarray_init): Declare.
* init.c (maybe_reject_flexarray_init): No longer static.
Add check for current_function_decl.
* parser.c (cp_parser_late_parse_one_default_arg): Reject
a default mem-initializer for a flexible array.

* g++.dg/ext/flexary23.C: New test.

From-SVN: r245641

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/init.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/flexary23.C [new file with mode: 0644]

index 8222541..90272d2 100644 (file)
@@ -1,3 +1,12 @@
+2017-02-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79535
+       * cp-tree.h (maybe_reject_flexarray_init): Declare.
+       * init.c (maybe_reject_flexarray_init): No longer static.
+       Add check for current_function_decl.
+       * parser.c (cp_parser_late_parse_one_default_arg): Reject
+       a default mem-initializer for a flexible array.
+
 2017-02-21  Jakub Jelinek  <jakub@redhat.com>
            Paolo Carlini  <paolo.carlini@oracle.com>
 
index 6675ee5..f53f744 100644 (file)
@@ -6069,6 +6069,7 @@ extern tree scalar_constant_value         (tree);
 extern tree decl_really_constant_value         (tree);
 extern int diagnose_uninitialized_cst_or_ref_member (tree, bool, bool);
 extern tree build_vtbl_address                  (tree);
+extern bool maybe_reject_flexarray_init                (tree, tree);
 
 /* in lex.c */
 extern void cxx_dup_lang_specific_decl         (tree);
index fa74226..13ade8a 100644 (file)
@@ -600,7 +600,7 @@ get_nsdmi (tree member, bool in_ctor)
 /* Diagnose the flexible array MEMBER if its INITializer is non-null
    and return true if so.  Otherwise return false.  */
 
-static bool
+bool
 maybe_reject_flexarray_init (tree member, tree init)
 {
   tree type = TREE_TYPE (member);
@@ -615,6 +615,7 @@ maybe_reject_flexarray_init (tree member, tree init)
      initializer list.  */
   location_t loc;
   if (DECL_INITIAL (member) == init
+      || !current_function_decl
       || DECL_DEFAULTED_FN (current_function_decl))
     loc = DECL_SOURCE_LOCATION (member);
   else
index 0146596..3992516 100644 (file)
@@ -27228,6 +27228,8 @@ cp_parser_late_parse_one_default_arg (cp_parser *parser, tree decl,
       if (TREE_CODE (decl) == PARM_DECL)
        parsed_arg = check_default_argument (parmtype, parsed_arg,
                                             tf_warning_or_error);
+      else if (maybe_reject_flexarray_init (decl, parsed_arg))
+       parsed_arg = error_mark_node;
       else
        parsed_arg = digest_nsdmi_init (decl, parsed_arg);
     }
index 1262b2e..b76d0a3 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79535
+       * g++.dg/ext/flexary23.C: New test.
+
 2017-02-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79654
diff --git a/gcc/testsuite/g++.dg/ext/flexary23.C b/gcc/testsuite/g++.dg/ext/flexary23.C
new file mode 100644 (file)
index 0000000..099e7fd
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/79535 - ICE with NSDMI and array
+// { dg-do compile { target c++14 } }
+// { dg-options -Wno-pedantic }
+
+struct A
+{
+  int b = 1;
+  int c = 2;
+  int x[] = { c, 3 }; // { dg-error "initializer for flexible array member" }
+};
+A a = { 4, 5 };