Patchwork C++ PATCH to expression printing of ref/ptr nops

login
register
mail settings
Submitter Jason Merrill
Date Sept. 24, 2010, 3:34 p.m.
Message ID <4C9CC51D.4060807@redhat.com>
Download mbox | patch
Permalink /patch/65654/
State New
Headers show

Comments

Jason Merrill - Sept. 24, 2010, 3:34 p.m.
A NOP_EXPR between a REFERENCE_TYPE and POINTER_TYPE with the same 
TREE_TYPE corresponds to a * or & operation in the language, so we 
should print it accordingly.

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

Patch

commit 913dab69ab98eaf30e5f409db4a88feeb1281d87
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Sep 24 15:13:08 2010 +0000

    	* error.c (dump_expr) [CASE_CONVERT]: Print conversion between
    	reference and pointer to the same type as "*" or "&".
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164597 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 981b71f..be3dd2c 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1949,8 +1949,21 @@  dump_expr (tree t, int flags)
     case VIEW_CONVERT_EXPR:
       {
 	tree op = TREE_OPERAND (t, 0);
+	tree ttype = TREE_TYPE (t);
+	tree optype = TREE_TYPE (op);
 
-	if (!same_type_p (TREE_TYPE (op), TREE_TYPE (t)))
+	if (TREE_CODE (ttype) != TREE_CODE (optype)
+	    && POINTER_TYPE_P (ttype)
+	    && POINTER_TYPE_P (optype)
+	    && same_type_p (TREE_TYPE (optype),
+			    TREE_TYPE (ttype)))
+	  {
+	    if (TREE_CODE (ttype) == REFERENCE_TYPE)
+	      dump_unary_op ("*", t, flags);
+	    else
+	      dump_unary_op ("&", t, flags);
+	  }
+	else if (!same_type_p (TREE_TYPE (op), TREE_TYPE (t)))
 	  {
 	    /* It is a cast, but we cannot tell whether it is a
 	       reinterpret or static cast. Use the C style notation.  */
diff --git a/gcc/testsuite/g++.dg/other/error10.C b/gcc/testsuite/g++.dg/other/error10.C
index 9e6da65..26f7ca5 100644
--- a/gcc/testsuite/g++.dg/other/error10.C
+++ b/gcc/testsuite/g++.dg/other/error10.C
@@ -6,7 +6,7 @@  template<int> struct A {};
 
 template<int N>
 void foo(const A<N> &a)
-{ -A<N>(a); } // { dg-error "\\(\\(const A<0>\\*\\)a\\)" "" }
+{ -A<N>(a); } // { dg-error "\\(\\* & a\\)" "" }
 
 void bar()
 {