From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112374 invoked by alias); 28 Apr 2017 15:29:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 112362 invoked by uid 89); 28 Apr 2017 15:29:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_MANYTO,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: mail-qk0-f182.google.com Received: from mail-qk0-f182.google.com (HELO mail-qk0-f182.google.com) (209.85.220.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 15:29:49 +0000 Received: by mail-qk0-f182.google.com with SMTP id u75so55393372qka.3 for ; Fri, 28 Apr 2017 08:29:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=820Z20IWUmAyBBwt8/mhzA6W4hf2LBjdLFCE953YiOA=; b=pjSzaIUFjXl1dSJ5Y+6GUWQQl5iaNXyrR6qeSYPvbstZ0DgOFI+lmQxLq4OrT/DtMw uMLLaTaXeyoPWp7m+hQWVEkpxRogqdxI8swMzf46R++Q6KYZz2kAb9AJaS59ojGlS+U2 ugc2X1GBRmw+rlaLw71QbfTmfXuq6HTgRpKgGKArI8lKF/K9GClxftwdAe11h9Nz4QTv yW4v0MBqBn1NT0ATgrCqmWbnSNbdCcZLeS1lRbbRxU2sStJ+35PYMiDFIFY4d0qOt+Yf G9hC5CpuSxRX0hNvz/vYh94M9wv0ULuMiyXTwNoETEMggR7Z3k5PHOhwEHxvK5OW+99t N9nA== X-Gm-Message-State: AN3rC/4WPiqB1BhrSLzgSCqNkyRhL7DBWOmgwwo6w0IwBwxwDerwnv+h CbPN1TqIyj3TBQ== X-Received: by 10.55.0.65 with SMTP id 62mr9603432qka.158.1493393390331; Fri, 28 Apr 2017 08:29:50 -0700 (PDT) Received: from localhost.localdomain (75-166-101-229.hlrn.qwest.net. [75.166.101.229]) by smtp.gmail.com with ESMTPSA id 1sm4072011qtb.40.2017.04.28.08.29.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Apr 2017 08:29:49 -0700 (PDT) Subject: Re: [PATCH] Implement a warning for bogus sizeof(pointer) / sizeof(pointer[0]) To: Bernd Edlinger , "gcc-patches@gcc.gnu.org" , Joseph Myers , Jason Merrill , Jeff Law , Richard Biener , Jakub Jelinek References: <776bb206-7b8e-1878-5411-3f1cdaabac05@gmail.com> <20432ae0-2c58-42a0-cc71-dd128187af45@gmail.com> From: Martin Sebor Message-ID: Date: Fri, 28 Apr 2017 16:27:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg01505.txt.bz2 On 04/28/2017 08:12 AM, Bernd Edlinger wrote: > On 04/28/17 00:52, Martin Sebor wrote: >>>> I suggest avoiding "element size" because the pointed-to argument >>>> need not be an array. Mentioning the types should help users better >>>> understand the problem (especially in C++ where types are often >>>> obscured by layers of templates). It might also be a nice touch >>>> to add a note pointing to the declaration of the first sizeof >>>> operand (if it's an object). >>>> >>> >>> Yes, many thanks for your suggestions. >>> >>> Do the new warning and info messages look right? >> >> Sorry for not replying sooner. The new warning looks good to >> me, with just one minor nit. For proper highlighting within >> the message, the expression should be quoted in a pair of %< >> and %> directives, like so: >> >> warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, >> "division % does " >> "not compute the number of array elements", >> type0, type1)) >> >> This way the whole quoted expression will be highlighted in >> the style appropriate for quoted text. >> >> Similarly, in the inform call, sizeof should be quoted in >> the same pair of %< and %> directives. >> > > Do you want me to change the %qT format strings to %T ? Yes, with the surrounding %< and %> the nested directives should use the unquoted forms, otherwise the printer would end up quoting both the whole expression and the type operand. FWIW, to help avoid this mistake, I think this might be something for GCC -Wformat to warn on and the pretty-printer to detect (and ICE on). Martin