Patchwork C++ PATCH for c++/49528 (omitting destructor for temporary with constant value)

login
register
mail settings
Submitter Jason Merrill
Date June 27, 2011, 1:08 a.m.
Message ID <4E07D809.3040909@redhat.com>
Download mbox | patch
Permalink /patch/102083/
State New
Headers show

Comments

Jason Merrill - June 27, 2011, 1:08 a.m.
But yes, I think checking for literal type is a better idea.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 81e093c1d6f2657c8c3c2abc2af559111ca82da4
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 26 15:23:00 2011 -0400

    	PR c++/49528
    	* semantics.c (potential_constant_expression_1): Check
    	for non-literality rather than cleanup.
    	(cxx_eval_constant_expression): Likewise.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5404c9f..d1af0c6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7020,11 +7020,10 @@  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 (!literal_type_p (TREE_TYPE (t)))
 	{
 	  if (!allow_non_constant)
-	    error ("temporary of type %qT needing destruction in a "
+	    error ("temporary of non-literal type %qT in a "
 		   "constant expression", TREE_TYPE (t));
 	  *non_constant_p = true;
 	  break;
@@ -7851,11 +7850,10 @@  potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
 					      want_rval, flags);
 
     case TARGET_EXPR:
-      /* A cleanup isn't constant.  */
-      if (TARGET_EXPR_CLEANUP (t))
+      if (!literal_type_p (TREE_TYPE (t)))
 	{
 	  if (flags & tf_error)
-	    error ("temporary of type %qT needing destruction in a "
+	    error ("temporary of non-literal type %qT in a "
 		   "constant expression", TREE_TYPE (t));
 	  return false;
 	}
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-cleanup.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-cleanup.C
index b3fb9a8..de17f3d 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-cleanup.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-cleanup.C
@@ -6,4 +6,4 @@  struct A
   ~A();
 };
 
-constexpr int i = A().i;	// { dg-error "destruction" }
+constexpr int i = A().i;	// { dg-error "non-literal" }