From 525c617d3b92c10f79d1ffc786fb87dbf0958f0b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 20 Feb 2011 18:18:01 -0500 Subject: [PATCH] re PR c++/46472 ([C++0X] constexpr is not constexpr) PR c++/46472 * method.c (process_subob_fn): Instantiate constexpr templates. * optimize.c (maybe_clone_body): Propagate DECL_DECLARED_CONSTEXPR_P. From-SVN: r170348 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/method.c | 13 +++++++++++-- gcc/cp/optimize.c | 1 + gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/constexpr-synth1.C | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-synth1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a40fd02141b..b867ef327bc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-02-20 Jason Merrill + + PR c++/46472 + * method.c (process_subob_fn): Instantiate constexpr templates. + * optimize.c (maybe_clone_body): Propagate DECL_DECLARED_CONSTEXPR_P. + 2011-02-20 Dodji Seketeli PR c++/46394 diff --git a/gcc/cp/method.c b/gcc/cp/method.c index bfe8a067a8b..47f18081063 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -941,8 +941,17 @@ process_subob_fn (tree fn, bool move_p, tree *spec_p, bool *trivial_p, goto bad; } - if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn)) - *constexpr_p = false; + if (constexpr_p) + { + /* If this is a specialization of a constexpr template, we need to + force the instantiation now so that we know whether or not it's + really constexpr. */ + if (DECL_DECLARED_CONSTEXPR_P (fn) && DECL_TEMPLATE_INSTANTIATION (fn) + && !DECL_TEMPLATE_INSTANTIATED (fn)) + instantiate_decl (fn, /*defer_ok*/false, /*expl_class*/false); + if (!DECL_DECLARED_CONSTEXPR_P (fn)) + *constexpr_p = false; + } return; diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c index b00bc28f030..ed59f91eff3 100644 --- a/gcc/cp/optimize.c +++ b/gcc/cp/optimize.c @@ -256,6 +256,7 @@ maybe_clone_body (tree fn) /* Update CLONE's source position information to match FN's. */ DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn); DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn); + DECL_DECLARED_CONSTEXPR_P (clone) = DECL_DECLARED_CONSTEXPR_P (fn); DECL_COMDAT (clone) = DECL_COMDAT (fn); DECL_WEAK (clone) = DECL_WEAK (fn); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7078fdbb85f..9eff5ffcd2f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-02-20 Jason Merrill + + * g++.dg/cpp0x/constexpr-synth1.C: New. + 2011-02-20 Nicola Pero * objc.dg/layout-2.m: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-synth1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-synth1.C new file mode 100644 index 00000000000..9830939806b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-synth1.C @@ -0,0 +1,14 @@ +// PR c++/46472 +// { dg-options -std=c++0x } + +template struct A { + T t; + constexpr A(){} +}; + +struct B +{ + A a; +}; + +B b; -- 2.30.2