From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27434 invoked by alias); 24 Feb 2009 15:10:15 -0000 Received: (qmail 27424 invoked by uid 22791); 24 Feb 2009 15:10:12 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_53 X-Spam-Check-By: sourceware.org Received: from mail-forward1.uio.no (HELO mail-forward1.uio.no) (129.240.10.70) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Feb 2009 15:10:05 +0000 Received: from exim by mail-out1.uio.no with local-bsmtp (Exim 4.69) (envelope-from ) id 1Lbyv5-0007U0-2i for gcc-help@gcc.gnu.org; Tue, 24 Feb 2009 16:10:03 +0100 Received: from mail-mx2.uio.no ([129.240.10.30]) by mail-out1.uio.no with esmtp (Exim 4.69) (envelope-from ) id 1Lbyv5-0007Tx-1b for gcc-help@gcc.gnu.org; Tue, 24 Feb 2009 16:10:03 +0100 Received: from cma-eivindlm.uio.no ([129.240.223.140] helo=ichi) by mail-mx2.uio.no with esmtp (Exim 4.69) (envelope-from ) id 1Lbyv4-0007L0-IE for gcc-help@gcc.gnu.org; Tue, 24 Feb 2009 16:10:03 +0100 Date: Tue, 24 Feb 2009 15:10:00 -0000 To: "gcc-help@gcc.gnu.org" Subject: Re: Where did the warning go? From: "Eivind LM" Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <204DEA5423F3BF47A6EE88C4E2979EC66BE32F0370@nambx04.corp.adobe.com> <49A400A3.9090508@ellipticsemi.com> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <49A400A3.9090508@ellipticsemi.com> User-Agent: Opera Mail/9.63 (Linux) X-UiO-Spam-info: not spam, SpamAssassin (score=-5.0, required=5.0, autolearn=disabled, UIO_MAIL_IS_INTERNAL=-5, uiobl=NO, uiouri=NO) X-UiO-Scanned: 1F1E3770469F9556E19F34254AC3C89AE705456D X-UiO-SPAM-Test: remote_host: 129.240.223.140 spam_score: -49 maxlevel 200 minaction 2 bait 0 mail/h: 1 total 557 max/h 82 blacklist 0 greylist 0 ratelimit 0 X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2009-02/txt/msg00182.txt.bz2 On Tue, 24 Feb 2009 15:13:55 +0100, Tom St Denis wrote: > Eivind LM wrote: >> It does of course depend on each case whether a warning is easy to >> avoid or not, and also if it warns about a real problem or not. But in >> any case, a warning can help me write code that more surely will do >> what I intend. For example the following code is not doing what I >> intended: >> >> #include >> void print(int a) { printf("%d\n", a); }; >> int main() { print(2.5); return 0; }; >> >> I think the problem in the code is both easy to avoid and serious, but >> I get no warning with -Wall and -Wextra (g++ 4.3). > That's because it's not undefined behaviour. "default" warnings should > be for things that are not guaranteed to have a known meaning or > behaviour. I think the warning should be part of -Wall, but I understand if you don't agree. Anyway this is not my point. I trust someone has good reasons for the selection of warnings included in -Wall. My points are: "-Wall" should be renamed, and a new flag should be added that would enable absolutely all warnings. > e.g. > > int a; > if (a == 4) { ... } > > Is undefined behaviour since a is unitialized. Compiling this example with -Wall and -Wextra gives me no warning with g++ (Debian 4.3.2-1.1) 4.3.2. Installed by apt-get today from Debian repositories. > float a; > a = 0; > if (a == 4) { ... } > > Is fine, but I should also point out "4" is an integral type that is > converted to float for the purpose of the expression "a == 4" . So by > your logic, it should also generate a warning. Yes, I would like a warning if I compare a float to an int. I would probably not compare two floats on equality anyway, but if I really had to, then I would write "4" as 4.0f. Compiling the second example with -Wall and -Wextra gives me no warning with the same compiler as above. > -Wall should really just enable every warning that has something to do > with behaviour that is not predictable. Fine, but the name should be changed. > -Weverything would be an appropriate name for every warning. Agree! :) Eivind