From: Xi Ruoyao <ryxi@stu.xidian.edu.cn>
To: Martin Sebor <msebor@gmail.com>, gcc-patches@gcc.gnu.org
Cc: ryxi@stu.xidian.edu.cn
Subject: Re: [PATCH 3/6] New warnings -Wstring-plus-{char, int} (PR c++/62181)
Date: Mon, 19 Jun 2017 17:35:00 -0000 [thread overview]
Message-ID: <1497893712.8943.3.camel@stu.xidian.edu.cn> (raw)
In-Reply-To: <43f3e36d-09d7-8075-5297-87db521558a8@gmail.com>
On 2017-06-19 10:30 -0600, Martin Sebor wrote:
> On 06/11/2017 07:34 PM, Xi Ruoyao wrote:
> > This patch adds warning option -Wstring-plus-char for C/C++.
> >
>
> +void
> +warn_if_string_plus_char (location_t loc, tree ptrtype, tree inttype)
> +{
> +Â Â if (POINTER_TYPE_P (ptrtype)
> +Â Â Â Â Â Â && type_main_variant_is_char (TREE_TYPE (ptrtype))
> +Â Â Â Â Â Â && type_main_variant_is_char (inttype))
> +Â Â Â Â warning_at (loc, OPT_Wstring_plus_char,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "add %qT to string pointer %qT does not append "
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "to the string", inttype, ptrtype);
>
> The text of the warning doesn't read like a grammatically correct
> sentence.  ("Adding a to b" would be correct.)
Yes. It's a typo.
> That said, I wonder if it should also be made more accurate.
> Based on c-c++-common/Wstring-plus-char.c for the snippet below
>
> Â Â Â char *a;
> Â Â Â const char *b;
> Â Â Â const char c = 'c';
> Â Â Â const char *d = a + c;
>
> it will print
>
> Â Â Â warning: add 'char' to 'char *' does not append to the string
>
> even though no string is apparent or need to exist in the program
> (a could point to an array of chars with no terminating NUL).
> I see Clang prints something similar (modulo the bad grammar) but
> I think it might be clearer if the warning instead read something
> like:
>
> Â Â Â adding 'char' to 'char *' does not append to a string
>
> or (if the warning were to trigger only for character constants
> like in Clang):
>
> Â Â Â adding 'char' to 'char *' does not append 'c' to the first operand
Clang 4.0 only warns for character constants. But Clang 5.0
(pre-release) also warns for variables with type char.
Which option should we take? Maybe -Wstring-plus-char={1,2} ?
> i.e., if the warning also included the value of the character
> constant.
>
> Martin
--
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University
next prev parent reply other threads:[~2017-06-19 17:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-12 1:26 [PATCH 0/6] " Xi Ruoyao
2017-06-12 1:31 ` [PATCH 1/6] " Xi Ruoyao
2017-06-12 1:32 ` [PATCH 2/6] " Xi Ruoyao
2017-06-19 16:51 ` Martin Sebor
2017-06-19 17:28 ` Xi Ruoyao
2017-06-19 18:44 ` Martin Sebor
2017-06-19 19:36 ` Xi Ruoyao
2017-06-22 10:26 ` Xi Ruoyao
2017-07-15 16:33 ` Gerald Pfeifer
2017-06-12 1:34 ` [PATCH 3/6] " Xi Ruoyao
2017-06-19 16:30 ` Martin Sebor
2017-06-19 17:35 ` Xi Ruoyao [this message]
2017-06-12 1:36 ` [PATCH 4/6] " Xi Ruoyao
2017-06-12 1:39 ` [PATCH 5/6] " Xi Ruoyao
2017-06-12 1:39 ` [PATCH 6/6] " Xi Ruoyao
2017-06-19 16:57 ` Martin Sebor
2017-06-19 12:43 ` [PING PATCH 0/6] " Xi Ruoyao
2017-06-19 16:20 ` [PATCH " Martin Sebor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1497893712.8943.3.camel@stu.xidian.edu.cn \
--to=ryxi@stu.xidian.edu.cn \
--cc=gcc-patches@gcc.gnu.org \
--cc=msebor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).