summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-26 14:00:33 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-26 14:00:33 +0000
commite3260d66ed0c89a4cd7249416b56ba81d5e2c960 (patch)
treeb9daf9f1abc1a91a7cacbb85a1df30a46c2c7cc5 /gcc/cp
parent197117e7ddc3012bc2805eb46c79096915e4a98d (diff)
downloadgcc-e3260d66ed0c89a4cd7249416b56ba81d5e2c960.tar.gz
PR c++/49528
* semantics.c (potential_constant_expression_1): A TARGET_EXPR with a cleanup isn't constant. (cxx_eval_constant_expression): Likewise. * init.c (expand_default_init): Use maybe_constant_init. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175409 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/init.c2
-rw-r--r--gcc/cp/semantics.c20
3 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3840f370ccf..117c13e9867 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2011-06-26 Jason Merrill <jason@redhat.com>
+
+ PR c++/49528
+ * semantics.c (potential_constant_expression_1): A TARGET_EXPR
+ with a cleanup isn't constant.
+ (cxx_eval_constant_expression): Likewise.
+ * init.c (expand_default_init): Use maybe_constant_init.
+
2011-06-24 Jakub Jelinek <jakub@redhat.com>
PR c++/46400
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3c347a4521f..3ceed90f3b5 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1514,7 +1514,7 @@ expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags,
tree fn = get_callee_fndecl (rval);
if (fn && DECL_DECLARED_CONSTEXPR_P (fn))
{
- tree e = maybe_constant_value (rval);
+ tree e = maybe_constant_init (rval);
if (TREE_CONSTANT (e))
rval = build2 (INIT_EXPR, type, exp, e);
}
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index f4aa350cb7c..5404c9f2a56 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7020,6 +7020,16 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t,
break;
case TARGET_EXPR:
+ /* A cleanup isn't constant. */
+ if (TARGET_EXPR_CLEANUP (t))
+ {
+ if (!allow_non_constant)
+ error ("temporary of type %qT needing destruction in a "
+ "constant expression", TREE_TYPE (t));
+ *non_constant_p = true;
+ break;
+ }
+ /* else fall through. */
case INIT_EXPR:
/* Pass false for 'addr' because these codes indicate
initialization of a temporary. */
@@ -7840,8 +7850,16 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
return potential_constant_expression_1 (TREE_OPERAND (t, 1),
want_rval, flags);
- case INIT_EXPR:
case TARGET_EXPR:
+ /* A cleanup isn't constant. */
+ if (TARGET_EXPR_CLEANUP (t))
+ {
+ if (flags & tf_error)
+ error ("temporary of type %qT needing destruction in a "
+ "constant expression", TREE_TYPE (t));
+ return false;
+ }
+ case INIT_EXPR:
return potential_constant_expression_1 (TREE_OPERAND (t, 1),
rval, flags);