This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 2/6] New warnings -Wstring-plus-{char, int} (PR c++/62181)
- From: Gerald Pfeifer <gerald at pfeifer dot com>
- To: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- Cc: Martin Sebor <msebor at gmail dot com>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 15 Jul 2017 18:33:48 +0200 (CEST)
- Subject: Re: [PATCH 2/6] New warnings -Wstring-plus-{char, int} (PR c++/62181)
- Authentication-results: sourceware.org; auth=none
- References: <1497230800.27153.4.camel@stu.xidian.edu.cn> <1497231174.27153.9.camel@stu.xidian.edu.cn> <699bc809-8e5f-b908-7b2e-0dd036a09462@gmail.com> <1497893292.8943.1.camel@stu.xidian.edu.cn> <7c4365db-fed6-f4c5-1231-2d8ac271fbe6@gmail.com> <1498127169.16226.1.camel@stu.xidian.edu.cn>
On Thu, 22 Jun 2017, Xi Ruoyao wrote:
> I created PR 81172. For const char *p = "123" + 'c' we should have:
>
> warning: offset 99 is above array bounds, the behaviour is
> undefined [-Warray-bounds]
> const char *p = "123" + 'c';
>
> and perhaps (for the case the pointer operand is a string or a string
> pointer):
> note: adding integer to a string does not append to the string.
I do think this makes sense. I'm really not convinced there is a
lot of code out there that uses the "123" + i idiom to create a pointer,
even if it is legitimate code, so a warning makes sense to me.
Gerald