From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2966 invoked by alias); 9 May 2012 12:29:04 -0000 Received: (qmail 2958 invoked by uid 22791); 9 May 2012 12:29:02 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 May 2012 12:28:50 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 42252290032; Wed, 9 May 2012 14:28:54 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XW+qHRDvTp4f; Wed, 9 May 2012 14:28:54 +0200 (CEST) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id D279C290008; Wed, 9 May 2012 14:28:53 +0200 (CEST) Subject: Re: [RFA] Emit a warning for ineffective set VAR = EXP command Mime-Version: 1.0 (Apple Message framework v1257) Content-Type: text/plain; charset=us-ascii From: Tristan Gingold In-Reply-To: <20120507193824.GW15555@adacore.com> Date: Wed, 09 May 2012 12:29:00 -0000 Cc: "Maciej W. Rozycki" , "gdb-patches@sourceware.org ml" Content-Transfer-Encoding: quoted-printable Message-Id: <419AD66E-6D21-40D6-97FE-1FF387117B7D@adacore.com> References: <8781499A-A489-42D0-80B1-75136331DBDB@adacore.com> <20120507193824.GW15555@adacore.com> To: Joel Brobecker X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-05/txt/msg00266.txt.bz2 On May 7, 2012, at 9:38 PM, Joel Brobecker wrote: >>> This warns about "set variable $j++" presumably -- should the warning b= e=20 >>> disabled for pre/post increments/decrements? >>=20 >> I am not opposed to disable warnings for pre/post inc/dec. >> But this usage is dubious (the help explicitly mentions VAR=3DEXP !) >>=20 >> Opinion ? >=20 > 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 th= at 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 * 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 =3D make_cleanup (free_current_contents, &expr); =20 - if (expr->nelts >=3D 1 - && expr->elts[0].opcode !=3D BINOP_ASSIGN - && expr->elts[0].opcode !=3D BINOP_ASSIGN_MODIFY - && expr->elts[0].opcode !=3D BINOP_COMMA) - warning (_("Expression is not an assignment (and might have no effect)= ")); + if (expr->nelts >=3D 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)")); + } =20 evaluate_expression (expr); do_cleanups (old_chain);