https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62181
--- Comment #7 from Xi Ruoyao <ryxi at stu dot xidian.edu.cn> --- (In reply to Martin Sebor from comment #6) > 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; > Clang-5.0 is doing this now for -Wstring-plus-int. I'll try to do this. > 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; > ... > } We should make a new PR requesting for clang -Warray-bounds as well. It's a part of meta-bug PR30334.