From: Alejandro Colomar <alx.manpages@gmail.com>
To: Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: Andrew Pinski <pinskia@gmail.com>,
gcc@gcc.gnu.org, Douglas McIlroy <douglas.mcilroy@dartmouth.edu>
Subject: Re: [whish] -Wunterminated-string-initialization: new warning
Date: Mon, 14 Nov 2022 14:46:59 +0100 [thread overview]
Message-ID: <4323c275-992a-1052-2110-d6d66dedc0b9@gmail.com> (raw)
In-Reply-To: <CAH6eHdT4OF1BM0X-e788hAEtxgqXE73XO_kxB6AFERM-am4AzA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2310 bytes --]
Hi Jonathan,
On 11/14/22 14:14, Jonathan Wakely wrote:
> On Mon, 14 Nov 2022 at 11:38, Alejandro Colomar via Gcc <gcc@gcc.gnu.org> wrote:
>>
>> Hi Andrew!
>>
>> On 11/13/22 23:12, Andrew Pinski wrote:
>>> On Sun, Nov 13, 2022 at 1:57 PM Alejandro Colomar via Gcc
>>> <gcc@gcc.gnu.org> wrote:
>>>>
>>>> Hi!
>>>>
>>>> I'd like to get warnings if I write the following code:
>>>>
>>>> char foo[3] = "foo";
>>>
>>> This should be easy to add as it is already part of the -Wc++-compat
>>> option as for C++ it is invalid code.
>>>
>>> <source>:2:19: warning: initializer-string for array of 'char' is too long
>>> 2 | char two[2] = "foo"; // 'f' 'o'
>>> | ^~~~~
>>> <source>:3:19: warning: initializer-string for array of 'char' is too
>>> long for C++ [-Wc++-compat]
>>> 3 | char three[3] = "foo"; // 'f' 'o' 'o'
>>> | ^~~~~
>>>
>>>
>>> ... (for your more complex case [though I needed to modify one of the
>>> strings to exactly 8]
>>>
>>> <source>:5:7: warning: initializer-string for array of 'char' is too
>>> long for C++ [-Wc++-compat]
>>> 5 | "01234567",
>>> | ^~~~~~~~~~
>>>
>>> else if (warn_cxx_compat
>>> && compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
>>> warning_at (init_loc, OPT_Wc___compat,
>>> ("initializer-string for array of %qT "
>>> "is too long for C++"), typ1);
>>>
>>> That is the current code which does this warning even so it is just a
>>> matter of adding an option to c-family/c.opt and then having
>>> c++-compat enable it and using that new option here.
>>>
>>> Thanks,
>>> Andrew Pinski
>>
>> Great! I'd like to implement it myself, as I've never written any GCC code yet,
>> so it's interesting to me. If you recall any (hopefully recent) case where a
>> similar thing happened (the warning was already implemented and only needed a
>> name), it might help me check how it was done.
>
> `git log gcc/c-family/c.opt` will show loads of changes adding warnings.
Thanks, I will check and try it, and come back if I have any doubts.
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2022-11-14 13:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-13 21:56 Alejandro Colomar
2022-11-13 22:12 ` Andrew Pinski
2022-11-14 11:37 ` Alejandro Colomar
2022-11-14 13:14 ` Jonathan Wakely
2022-11-14 13:41 ` unterminated string literals (was: [whish] -Wunterminated-string-initialization: new warning) Alejandro Colomar
2022-11-14 13:46 ` Alejandro Colomar [this message]
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=4323c275-992a-1052-2110-d6d66dedc0b9@gmail.com \
--to=alx.manpages@gmail.com \
--cc=douglas.mcilroy@dartmouth.edu \
--cc=gcc@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
--cc=pinskia@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).