On 06/11/2017 07:32 PM, Xi Ruoyao wrote:
This patch adds warning option -Wstring-plus-int for C/C++.

gcc/ChangeLog:

2017-06-12  Xi Ruoyao  <r...@stu.xidian.edu.cn>

        * c-family/c.opt: New option -Wstring-plus-int.
        * c-family/c-common.c (pointer_int_sum): Checking for
        -Wstring-plus-int.

This is a very useful warning but I would suggest to word it
in terms of what it actually does rather than what it might be
intended to do.  E.g., for

  const char *p = "123" + 7;

issue

  warning: offset 7 exceeds the upper bound 3 of the array

rather than

  warning: adding 'int' to a string does not append to the string

(I have trouble envisioning on what grounds someone might expect
the addition to have this effect.)

Given that the warning only triggers when the upper bound of
an array is exceeded I would also suggest to consider including
the warning in -Warray-bounds.  (With that, it would be useful
to also detect exceeding the upper bound of non-literal arrays
as well.)

Martin

Reply via email to