This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Emit a warning for ineffective set VAR = EXP command
On May 7, 2012, at 9:38 PM, Joel Brobecker wrote:
>>> This warns about "set variable $j++" presumably -- should the warning be
>>> disabled for pre/post increments/decrements?
>>
>> I am not opposed to disable warnings for pre/post inc/dec.
>> But this usage is dubious (the help explicitly mentions VAR=EXP !)
>>
>> Opinion ?
>
> I think we should avoid the warning for pre/post inc/dec. This
> type of expression might be a little outside the method proposed
> in our documentation, but I think it's still a perfectly valid
> expression that results in an assignment being performed.
I don't know who should approve this adjustment, but here is the version that deals with pre/post inc/dec.
Note that it still warns for expressions such as i++ * 2.
Tested on set-nowarns.exp.
Tristan.
2012-05-09 Tristan Gingold <gingold@adacore.com>
* printcmd.c (set_command): Add pre/post inc/dec.
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 79e38f2..fa76296 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1080,11 +1080,21 @@ set_command (char *exp, int from_tty)
struct cleanup *old_chain =
make_cleanup (free_current_contents, &expr);
- if (expr->nelts >= 1
- && expr->elts[0].opcode != BINOP_ASSIGN
- && expr->elts[0].opcode != BINOP_ASSIGN_MODIFY
- && expr->elts[0].opcode != BINOP_COMMA)
- warning (_("Expression is not an assignment (and might have no effect)"));
+ if (expr->nelts >= 1)
+ switch (expr->elts[0].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);
do_cleanups (old_chain);