From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8335 invoked by alias); 22 Apr 2012 22:25:51 -0000 Received: (qmail 8326 invoked by uid 22791); 22 Apr 2012 22:25:50 -0000 X-SWARE-Spam-Status: No, hits=-5.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_PW X-Spam-Check-By: sourceware.org Received: from mail-vb0-f41.google.com (HELO mail-vb0-f41.google.com) (209.85.212.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 22 Apr 2012 22:25:36 +0000 Received: by vbbey12 with SMTP id ey12so9429041vbb.0 for ; Sun, 22 Apr 2012 15:25:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.72.138 with SMTP id d10mr11290902vdv.80.1335133536153; Sun, 22 Apr 2012 15:25:36 -0700 (PDT) Received: by 10.220.148.146 with HTTP; Sun, 22 Apr 2012 15:25:36 -0700 (PDT) Reply-To: noloader@gmail.com In-Reply-To: References: <20120422082240.GA21311@host2.jankratochvil.net> Date: Sun, 22 Apr 2012 22:25:00 -0000 Message-ID: Subject: Re: Switch -Wunused-variable on? From: Jeffrey Walton To: Sergio Durigan Junior Cc: Jan Kratochvil , gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2012-04/txt/msg00178.txt.bz2 On Sun, Apr 22, 2012 at 4:24 PM, Sergio Durigan Junior wrote: > On Sunday, April 22 2012, Jan Kratochvil wrote: > >> On Sun, 22 Apr 2012 09:14:44 +0200, Sergio Durigan Junior wrote: >>> However, before continuing to prepare this patch, I would like what you >>> think about enabling -Wunused-variable by default in the building. >> >> There are more useful -Wunused* options, GDB uses now: >> =C2=A0 =C2=A0 =C2=A0 -Wno-unused -Wunused-value -Wunused-function > > Sorry, do you mean that there are more useful -Wunused* flags than > -Wunused-variable? > >> IIRC the counterargument for -Wunused-variable was that GDB contains var= ious >> #if-compiled code where is a nightmare to get the code right with matchi= ng >> #if-clauses also for the variables being used by various #if-compiled co= de >> chunks. =C2=A0I could not find that mail now in the time I gave to it. > > Yes, this is a counter-argument, and I was also thinking about it. =C2=A0I > don't know how people prefer to deal with this issue, but something > like: > > #define USED_VAR(var) ((void) var) I use this technique when using -Wall. It even works on Visual Studio, so the technique is portable. >> I believe more -Wunused* would be worth it, maybe the mail was before Jo= el >> started to disable -Werror for releases so that claim about problematic >> #if-clauses is no longer valid. > > Yes, I believe the more useful warnings we have, the better. In general, you will encounter a lot of resistance to increasing warning. For example, try to add -Wall -Wextra -Wconversion -Wstrict-overflow to CFLAGS or CXXFLAGS on some project. Some even refute the results even when they are valid findings. For example, when static analysis warned the kernel's sys_prctl was comparing an unsigned value against less than zero, Jesper Juhl offered a patch to clean up the code. Linus Torvalds howled =E2=80=9CNo, you don't do this... GCC is crap.=E2=80=9D For the full discussion, see "[PATCH] Don't compare unsigned variable for <0 in sys_prctl()" (http://linux.derkeiler.com/Mailing-Lists/Kernel/2006-11/msg08325.html) from the Linux Kernel mailing list. I live and die by GCC's static analysis capabilities. I've got stuff that has been in the field for years and never taken a bug report or crashed. But I also validate all parameter in each function (C/C++ makes no guarantees on a call graph), I also check all return values, assert *everything* in debug builds (the best code is code that debugs itself), and write negative test cases. I could not care less about positive test cases since you could hire a kid from a third world country to copy/paste code that passes positive tests. If I got pwned as often as the l33t k3rn3l hAck3rz, I would consider finding a new profession. Worst, the tools are already available to find an fix most of the low hanging fruit. Arrogance and ignorance is a big problem in the community... Jeff