public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Joseph Myers <joseph@codesourcery.com>,
	Jason Merrill <jason@redhat.com>, Jeff Law <law@redhat.com>,
	Richard Biener <rguenther@suse.de>,
	Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] Implement a warning for bogus sizeof(pointer) / sizeof(pointer[0])
Date: Fri, 28 Apr 2017 16:27:00 -0000	[thread overview]
Message-ID: <c2630692-a843-4396-3c78-12149bf284c4@gmail.com> (raw)
In-Reply-To: <AM4PR0701MB2162E9E0B096CBC57645F05CE4130@AM4PR0701MB2162.eurprd07.prod.outlook.com>

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 %<sizeof (%T) / sizeof (%T)%> 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

  reply	other threads:[~2017-04-28 15:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 21:33 Bernd Edlinger
2017-04-22  6:51 ` Martin Sebor
2017-04-22 17:50   ` Bernd Edlinger
2017-04-28  3:23     ` Martin Sebor
2017-04-28 14:42       ` Bernd Edlinger
2017-04-28 16:27         ` Martin Sebor [this message]
2017-04-28 17:20           ` Bernd Edlinger
2017-05-01 15:54             ` Jason Merrill
2017-05-02 13:38               ` Bernd Edlinger
2017-05-03 13:15                 ` Jason Merrill
2017-05-12 16:56                   ` [PING] " Bernd Edlinger
2017-06-01 16:03                     ` [PING**2] " Bernd Edlinger
2017-06-01 22:09                       ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c2630692-a843-4396-3c78-12149bf284c4@gmail.com \
    --to=msebor@gmail.com \
    --cc=bernd.edlinger@hotmail.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=law@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).