diff mbox

Small C++ PATCH to reorganize handling of constexpr refs

Message ID 4E46DAA4.4010600@redhat.com
State New
Headers show

Commit Message

Jason Merrill Aug. 13, 2011, 8:12 p.m. UTC
While looking at 48370, I noticed that this bit of code in 
initialize_reference really ought to be in grok_reference_init instead, 
since it only applied to top-level references.

Tested x86_64-pc-linux-gnu, applied to trunk.
diff mbox

Patch

commit 82efe7318e5cd58632043cc92624b0d31d9ad0d4
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 12 17:09:20 2011 -0400

    	* decl.c (grok_reference_init): Handle constexpr here.
    	* call.c (initialize_reference): Not here.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index e8fb68d..d2700cb 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8820,12 +8820,6 @@  initialize_reference (tree type, tree expr, tree decl, tree *cleanup,
 		    (build_pointer_type (base_conv_type), expr,
 		     complain));
 	  expr = build_nop (type, expr);
-	  if (DECL_DECLARED_CONSTEXPR_P (decl))
-	    {
-	      expr = cxx_constant_value (expr);
-	      DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
-		= reduced_constant_expression_p (expr);
-	    }
 	}
     }
   else
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1db0748..c125f05 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -4597,6 +4597,12 @@  grok_reference_init (tree decl, tree type, tree init, tree *cleanup)
      explicitly); we need to allow the temporary to be initialized
      first.  */
   tmp = initialize_reference (type, init, decl, cleanup, tf_warning_or_error);
+  if (DECL_DECLARED_CONSTEXPR_P (decl))
+    {
+      tmp = cxx_constant_value (tmp);
+      DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
+	= reduced_constant_expression_p (tmp);
+    }
 
   if (tmp == error_mark_node)
     return NULL_TREE;