From 8e9589bd6b308700c8601e802739b4d8f4d4cb83 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 26 Feb 2018 16:55:41 -0500 Subject: [PATCH] PR c++/84559 - ICE with constexpr VLA. * constexpr.c (ensure_literal_type_for_constexpr_object): Check for constexpr variable with VLA type. From-SVN: r258015 --- 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 "" } +} -- 2.30.2