[PATCH 203/203] Remove some null checks

Tom Tromey tom@tromey.com
Fri Jan 1 21:47:23 GMT 2021


When not parsing for completion, parse_expression ensures that the
resulting expression has operations.  This patch removes a couple of
unnecessary checks for this situation.

gdb/ChangeLog
2021-01-01  Tom Tromey  <tom@tromey.com>

	* printcmd.c (set_command): Remove null check.
	* value.c (init_if_undefined_command): Remove null check.
---
 gdb/ChangeLog  |  5 +++++
 gdb/printcmd.c | 29 ++++++++++++++---------------
 gdb/value.c    |  2 +-
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 484a2dbf228..c3e75de0bce 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1373,21 +1373,20 @@ set_command (const char *exp, int from_tty)
 {
   expression_up expr = parse_expression (exp);
 
-  if (expr->op != nullptr)
-    switch (expr->op->opcode ())
-      {
-      case UNOP_PREINCREMENT:
-      case UNOP_POSTINCREMENT:
-      case UNOP_PREDECREMENT:
-      case UNOP_POSTDECREMENT:
-      case BINOP_ASSIGN:
-      case BINOP_ASSIGN_MODIFY:
-      case BINOP_COMMA:
-	break;
-      default:
-	warning
-	  (_("Expression is not an assignment (and might have no effect)"));
-      }
+  switch (expr->op->opcode ())
+    {
+    case UNOP_PREINCREMENT:
+    case UNOP_POSTINCREMENT:
+    case UNOP_PREDECREMENT:
+    case UNOP_POSTDECREMENT:
+    case BINOP_ASSIGN:
+    case BINOP_ASSIGN_MODIFY:
+    case BINOP_COMMA:
+      break;
+    default:
+      warning
+	(_("Expression is not an assignment (and might have no effect)"));
+    }
 
   evaluate_expression (expr.get ());
 }
diff --git a/gdb/value.c b/gdb/value.c
index 7a9128df642..1bd43a53db6 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1982,7 +1982,7 @@ init_if_undefined_command (const char* args, int from_tty)
   /* Validate the expression.
      Was the expression an assignment?
      Or even an expression at all?  */
-  if (expr->op == nullptr || expr->first_opcode () != BINOP_ASSIGN)
+  if (expr->first_opcode () != BINOP_ASSIGN)
     error (_("Init-if-undefined requires an assignment expression."));
 
   /* Extract the variable from the parsed expression.  */
-- 
2.26.2



More information about the Gdb-patches mailing list