Fix unary + in Ada
authorTom Tromey <tromey@adacore.com>
Mon, 15 Mar 2021 14:20:24 +0000 (08:20 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 15 Mar 2021 14:20:24 +0000 (08:20 -0600)
My previous Ada patches introduced a bug that I found after checkin.
I had incorrectly implemented unary +.  There was a test for the
overloaded case, but no test for the ordinary case.

This patch adds the tests and fixes the bug.
Tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

* ada-exp.y (simple_exp): Always push a result for unary '+'.

gdb/testsuite/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

* gdb.ada/fixed_points.exp: Add tests of unary + and -.

gdb/ChangeLog
gdb/ada-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/fixed_points.exp

index d7f237edc0787aa8af1b43c41c08b2d7f1b5f1c9..ff0cc2cd1a449b4488410055d092ee1d5794c342 100644 (file)
@@ -1,3 +1,7 @@
+2021-03-15  Tom Tromey  <tromey@adacore.com>
+
+       * ada-exp.y (simple_exp): Always push a result for unary '+'.
+
 2021-03-15  Tom Tromey  <tromey@adacore.com>
 
        * ada-lang.c (ada_unop_ind_operation::evaluate): Call
index e8ffb8e1040b430ff6c6acb3d29a264437ccf493..146b1acbe14174783f8dc599195616f1924ddfea 100644 (file)
@@ -589,12 +589,14 @@ simple_exp :      '+' simple_exp    %prec UNARY
                          operation_up arg = ada_pop ();
                          operation_up empty;
 
-                         /* We only need to handle the overloading
-                            case here, not anything else.  */
+                         /* If an overloaded operator was found, use
+                            it.  Otherwise, unary + has no effect and
+                            the argument can be pushed instead.  */
                          operation_up call = maybe_overload (UNOP_PLUS, arg,
                                                              empty);
                          if (call != nullptr)
-                           pstate->push (std::move (call));
+                           arg = std::move (call);
+                         pstate->push (std::move (arg));
                        }
        ;
 
index aa6cacb6ada44e0f7a7260603f60b9e7c60df237..6ed26d1979f8235f87d429ac45d09587f8ec66df 100644 (file)
@@ -1,3 +1,7 @@
+2021-03-15  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.ada/fixed_points.exp: Add tests of unary + and -.
+
 2021-03-15  Tom Tromey  <tromey@adacore.com>
 
        * gdb.ada/varsize_limit.exp: Add new test.
index 7267c3181ed5569ff516f17a12bc33a8f53e2df5..69565e774908e5f5724530faab14b21c2eaee72e 100644 (file)
@@ -76,6 +76,11 @@ foreach_with_prefix scenario {all minimal} {
     gdb_test "print fp2_var - 0" \
        " = -0.01"
 
+    gdb_test "print + fp2_var" \
+       " = -0.01"
+    gdb_test "print - fp2_var" \
+       " = 0.01"
+
     set fp4 "= 2e-07"
     gdb_test "print fp4_var" $fp4
     gdb_test "print fp4_var * 1" $fp4