From: Marek Polacek Date: Tue, 21 Feb 2017 20:23:09 +0000 (+0000) Subject: re PR c++/79535 (ICE in verify_ctor_sanity, at cp/constexpr.c:2636) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a232a1cb1792bef3776dd4bddb7ef484790f8648;p=gcc.git re PR c++/79535 (ICE in verify_ctor_sanity, at cp/constexpr.c:2636) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 82225414bf7..90272d2638e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2017-02-21 Marek Polacek + + 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 Paolo Carlini diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6675ee5bb50..f53f7442bc9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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); diff --git a/gcc/cp/init.c b/gcc/cp/init.c index fa742268dc0..13ade8a616b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0146596d154..3992516de0e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1262b2eaa79..b76d0a31f86 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-21 Marek Polacek + + PR c++/79535 + * g++.dg/ext/flexary23.C: New test. + 2017-02-21 Jakub Jelinek 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 index 00000000000..099e7fd2938 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary23.C @@ -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 };