This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] fix for c++/2416


Hello,

As described in the bug report 2416, the problem is with casting to a reference. The attached patch should fix this.

Testing on head, no change in pass rate encountered (probably suggesting there is no test case for this - sample code in the bug report should be a good starting point).

Thanks,

Aleksandar Ristovski
QNX Software Systems

2008-02-27 Aleksandar Ristovski <aristovski@qnx.com>

	* eval.c (evaluate_subexp_standard): UNOP_CAST use
	value_cast_pointers when casting reference to reference. Print
	error when reference/non-reference mix.
	* value.c (value_as_address): Call coerce_array only on arrays.
	(unpack_long): Cover C++ cases TYPE_CODE_STRUCT and UNION.


Index: gdb/eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.80
diff -u -p -r1.80 eval.c
--- gdb/eval.c	4 Feb 2008 00:23:04 -0000	1.80
+++ gdb/eval.c	27 Feb 2008 17:01:03 -0000
@@ -1985,8 +1985,18 @@ evaluate_subexp_standard (struct type *e
       arg1 = evaluate_subexp (type, exp, pos, noside);
       if (noside == EVAL_SKIP)
 	goto nosideret;
-      if (type != value_type (arg1))
-	arg1 = value_cast (type, arg1);
+      if (type != value_type (arg1)) 
+	{
+	  if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_REF
+	      && TYPE_CODE (type) == TYPE_CODE_REF)
+	    arg1 = value_cast_pointers (type, arg1);
+	  else if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_REF
+		   && TYPE_CODE (type) != TYPE_CODE_REF)
+	    arg1 = value_cast (type, arg1);
+	  else /* We can not do much here.  */
+	    error (_("Attempt to cast to reference type from non-reference "\
+		     "type or vice versa."));
+	}
       return arg1;
 
     case UNOP_MEMVAL:
Index: gdb/value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.57
diff -u -p -r1.57 value.c
--- gdb/value.c	18 Jan 2008 17:07:40 -0000	1.57
+++ gdb/value.c	27 Feb 2008 17:01:03 -0000
@@ -1039,7 +1039,8 @@ value_as_address (struct value *val)
       || TYPE_CODE (value_type (val)) == TYPE_CODE_METHOD)
     return VALUE_ADDRESS (val);
 
-  val = coerce_array (val);
+  if (TYPE_CODE (value_type (val)) == TYPE_CODE_ARRAY)
+    val = coerce_array (val);
 
   /* Some architectures (e.g. Harvard), map instruction and data
      addresses onto a single large unified address space.  For
@@ -1120,6 +1121,8 @@ unpack_long (struct type *type, const gd
     case TYPE_CODE_CHAR:
     case TYPE_CODE_RANGE:
     case TYPE_CODE_MEMBERPTR:
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
       if (nosign)
 	return extract_unsigned_integer (valaddr, len);
       else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]