https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62181

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
With constant arguments (or those whose value or range is known), GCC should
warn on the first declaration in comment #0 (copied below) not necessarily
because the addition doesn't append 'c' to "aa" (i.e., with -Wstring-plus-char
warns) but mainly because it results in an invalid pointer.

  const char *a = "aa" + 'c';

GCC should warn for a constant operand that results in an out-of-bounds pointer
regardless of its type, such as the following:

  const char *a = "aa" + 4;

GCC could (and, in my view, should) also warn on the following where the value
of i isn't known but where its range is such that the addition will never
result in a valid pointer:

  void f (int i)
  {
    if (i < 4) return;
    const char *a = "aa" + i;
    ...
  }

Reply via email to