[PATCH] Implement a warning for bogus sizeof(pointer) / sizeof(pointer[0])

Jason Merrill jason@redhat.com
Wed May 3 13:15:00 GMT 2017


On Tue, May 2, 2017 at 9:26 AM, Bernd Edlinger
<bernd.edlinger@hotmail.de> wrote:
> On 05/01/17 17:54, Jason Merrill wrote:
>> On Fri, Apr 28, 2017 at 1:05 PM, Bernd Edlinger
>> <bernd.edlinger@hotmail.de> wrote:
>>> On 04/28/17 17:29, Martin Sebor wrote:
>>>> On 04/28/2017 08:12 AM, Bernd Edlinger wrote:
>>>>>
>>>>> 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).
>>>>
>>>
>>> Ah, now I understand.  That's pretty advanced.
>>>
>>> Here is the modified patch with correct quoting of the expression.
>>>
>>> Bootstrap and reg-testing on x86_64-pc-linux-gnu.
>>
>>> * cp-gimplify.c (cp_fold): Implement the -Wsizeof_pointer_div warning.
>>
>> I think this warning belongs in cp_build_binary_op rather than cp_fold.
>>
>
> Done, as suggested.

The pattern in that function is to treat all *_DIV_EXPR the same; I
don't think we need to break that pattern with this patch.  So please
move the new code after the other DIV case labels.  With that the C++
changes are OK.

Jason



More information about the Gcc-patches mailing list