From d3a9902e523f81f07e765b2553dde7019aa098fb Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 18 Jan 2018 15:02:06 -0500 Subject: [PATCH] PR c++/82461 - constexpr list-initialized member * constexpr.c (potential_constant_expression_1): Check TARGET_EXPR_DIRECT_INIT_P. From-SVN: r256860 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 3 ++- gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2de9dcb06d5..2240913b0a7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-01-18 Jason Merrill + + PR c++/82461 - constexpr list-initialized member + * constexpr.c (potential_constant_expression_1): Check + TARGET_EXPR_DIRECT_INIT_P. + 2018-01-18 Paolo Carlini PR c++/81013 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 8984613aa41..9a548d29bbc 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5726,7 +5726,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, return RECUR (TREE_OPERAND (t, 1), want_rval); case TARGET_EXPR: - if (!literal_type_p (TREE_TYPE (t))) + if (!TARGET_EXPR_DIRECT_INIT_P (t) + && !literal_type_p (TREE_TYPE (t))) { if (flags & tf_error) { diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C new file mode 100644 index 00000000000..780a64dbbc4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C @@ -0,0 +1,20 @@ +// PR c++/82461 +// { dg-do compile { target c++11 } } + +class A { +private: +public: + constexpr A() {} + ~A() {} +}; + +class B { +private: + A a; +public: + constexpr B() : a{} {} +// works +// constexpr B() : a() {} + + ~B() {} +}; -- 2.30.2