From 2787914706395bf7864bdc76491ada1b0a552cae Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 23 Aug 2011 12:03:01 -0400 Subject: [PATCH] re PR c++/50024 ([C++0x] [4.7 Regression] crash when using braced initialization in member function of template) PR c++/50024 * semantics.c (maybe_constant_value): Don't try to fold { }. * pt.c (build_non_dependent_expr): Don't wrap { }. * init.c (build_value_init): Allow scalar value-init in templates. From-SVN: r177994 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/init.c | 2 +- gcc/cp/pt.c | 4 ++++ gcc/cp/semantics.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C | 15 +++++++++++++++ 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 524a685da24..0f60bcb313a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2011-08-23 Jason Merrill + + PR c++/50024 + * semantics.c (maybe_constant_value): Don't try to fold { }. + * pt.c (build_non_dependent_expr): Don't wrap { }. + * init.c (build_value_init): Allow scalar value-init in templates. + 2011-08-23 Jason Merrill * semantics.c (potential_constant_expression_1): Allow 'this'. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4fa627ba8c0..847f5199f1b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -330,7 +330,7 @@ build_value_init (tree type, tsubst_flags_t complain) constructor. */ /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ - gcc_assert (!processing_template_decl); + gcc_assert (!processing_template_decl || SCALAR_TYPE_P (type)); if (CLASS_TYPE_P (type)) { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ed4fe726c20..3f9a4c04224 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19669,6 +19669,10 @@ build_non_dependent_expr (tree expr) if (TREE_CODE (expr) == THROW_EXPR) return expr; + /* Don't wrap an initializer list, we need to be able to look inside. */ + if (BRACE_ENCLOSED_INITIALIZER_P (expr)) + return expr; + if (TREE_CODE (expr) == COND_EXPR) return build3 (COND_EXPR, TREE_TYPE (expr), diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1f6b49a8472..2f62e351139 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7542,6 +7542,7 @@ maybe_constant_value (tree t) if (type_dependent_expression_p (t) || type_unknown_p (t) + || BRACE_ENCLOSED_INITIALIZER_P (t) || !potential_constant_expression (t) || value_dependent_expression_p (t)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e3c521cd143..fe3688826e1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-08-23 Jason Merrill + + PR c++/50024 + * g++.dg/cpp0x/constexpr-initlist5.C: New. + 2011-08-23 Jakub Jelinek PR c++/50158 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C new file mode 100644 index 00000000000..97f03999802 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist5.C @@ -0,0 +1,15 @@ +// PR c++/50024 +// { dg-options -std=c++0x } + +template< class T > +struct Container +{ + Container(){ + int* ptr = new int{}; + } +}; + +int main() { + Container< int > c; +} +