From fdafeeb77fda0afb9260ed55afcffeafcb35b8b8 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 26 Feb 2018 21:55:41 +0000 Subject: PR c++/84559 - ICE with constexpr VLA. * constexpr.c (ensure_literal_type_for_constexpr_object): Check for constexpr variable with VLA type. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258015 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 7 +++++++ gcc/testsuite/g++.dg/ext/constexpr-vla5.C | 7 +++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/constexpr-vla5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 14f899c1881..3a2a17d5720 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-26 Jason Merrill + + PR c++/84559 - ICE with constexpr VLA. + * constexpr.c (ensure_literal_type_for_constexpr_object): Check + for constexpr variable with VLA type. + 2018-02-26 Jakub Jelinek PR c++/84558 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b3de62a5bea..4bbdbf43487 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -112,6 +112,13 @@ ensure_literal_type_for_constexpr_object (tree decl) cp_function_chain->invalid_constexpr = true; } } + else if (DECL_DECLARED_CONSTEXPR_P (decl) + && variably_modified_type_p (type, NULL_TREE)) + { + error ("% variable %qD has variably-modified type %qT", + decl, type); + decl = error_mark_node; + } } return decl; } diff --git a/gcc/testsuite/g++.dg/ext/constexpr-vla5.C b/gcc/testsuite/g++.dg/ext/constexpr-vla5.C new file mode 100644 index 00000000000..565d40ab077 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/constexpr-vla5.C @@ -0,0 +1,7 @@ +// PR c++/84559 +// { dg-do compile { target c++11 } } + +void foo(int i) +{ + constexpr char x[i] = ""; // { dg-error "" } +} -- cgit v1.2.1