@@ -42,6 +42,18 @@ f2 (Child &&C)
return f1 (std::move (C)); /* Set breakpoint marker2 here. */
}
+int
+f3 (int &&var_i)
+{
+ return var_i + 1;
+}
+
+int
+f4 (float &&var_f)
+{
+ return static_cast <int> (var_f);
+}
+
struct OtherParent
{
OtherParent (int other_id0) : other_id (other_id0) { }
@@ -65,6 +77,10 @@ mf2 (MultiChild &&C)
return mf1 (std::move (C));
}
+/* These are used from within GDB. */
+int global_int = 7;
+float global_float = 3.5f;
+
int
main ()
{
@@ -81,5 +97,8 @@ main ()
mf2 (std::move (MQ)); /* Set breakpoint MQ here. */
+ (void) f3 (-1);
+ (void) f4 (3.5);
+
return 0;
}
@@ -40,6 +40,15 @@ set t "print value of f1 on (Child&&) in main"
gdb_start_again "marker1 here" $t
gdb_test "print f1(static_cast<Child&&>(Q))" ".* = 40.*" $t
+gdb_test "print f3(static_cast<int&&> (global_int))" " = 8"
+gdb_test "print f4(static_cast<float&&> (global_float))" " = 3"
+
+gdb_test "print static_cast<int&> (global_int)" " = \\(int &\\) @$hex: 7"
+gdb_test "print static_cast<int&&> (global_int)" " = \\(int &&\\) @$hex: 7"
+
+gdb_test "print static_cast<float&> (global_float)" " = \\(float &\\) @$hex: 3\\.$decimal"
+gdb_test "print static_cast<float&&> (global_float)" " = \\(float &&\\) @$hex: 3\\.$decimal"
+
set t "print value of f2 on (Child&&) in main"
gdb_start_again "marker1 here" $t
gdb_test "print f2(static_cast<Child&&>(Q))" ".* = 40.*" $t
@@ -415,8 +415,25 @@ value_cast (struct type *type, struct value *arg2)
int convert_to_boolean = 0;
- if (value_type (arg2) == type)
- return arg2;
+ /* TYPE might be equal in meaning to the existing type of ARG2, but for
+ many reasons, might be a different type object (e.g. TYPE might be a
+ gdbarch owned type, while VALUE_TYPE (ARG2) could be an objfile owned
+ type).
+
+ In this case we want to preserve the LVAL of ARG2 as this allows the
+ resulting value to be used in more places. We do this by calling
+ VALUE_COPY if appropriate. */
+ if (types_deeply_equal (value_type (arg2), type))
+ {
+ /* If the types are exactly equal then we can avoid creating a new
+ value completely. */
+ if (value_type (arg2) != type)
+ {
+ arg2 = value_copy (arg2);
+ deprecated_set_value_type (arg2, type);
+ }
+ return arg2;
+ }
if (is_fixed_point_type (type))
return value_cast_to_fixed_point (type, arg2);