Patchwork C++ PATCH to type of reference temporaries

login
register
mail settings
Submitter Jason Merrill
Date Sept. 16, 2010, midnight
Message ID <4C915E29.4020403@redhat.com>
Download mbox | patch
Permalink /patch/64929/
State New
Headers show

Comments

Jason Merrill - Sept. 16, 2010, midnight
While working on a constexpr bug, I noticed that we were giving the 
wrong type to the underlying temporaries for references.  They should 
have the underlying type of the reference, not the type of the initializer.

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

Patch

commit 862fc9f3493ea633557772a36ebb446e740d9711
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Sep 15 14:06:42 2010 -0400

    	* call.c (convert_like_real): Use the underlying type of the
    	reference for the temporary.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 37c6269..2b9b848 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -5207,10 +5207,16 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 	    || TREE_CODE (expr) == CONSTRUCTOR
 	    || TREE_CODE (expr) == VA_ARG_EXPR)
 	  {
-	    tree type = convs->u.next->type;
+	    /* Otherwise, a temporary of type "cv1 T1" is created and
+	       initialized from the initializer expression using the rules
+	       for a non-reference copy-initialization (8.5).  */
+
+	    tree type = TREE_TYPE (ref_type);
 	    cp_lvalue_kind lvalue = real_lvalue_p (expr);
 
-	    if (!CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type))
+	    gcc_assert (same_type_ignoring_top_level_qualifiers_p
+			(type, convs->u.next->type));
+	    if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
 		&& !TYPE_REF_IS_RVALUE (ref_type))
 	      {
 		if (complain & tf_error)