From: Jonny Grant <jg@jguk.org>
To: Martin Sebor <msebor@gmail.com>, gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: gcc warn unreached else {}
Date: Thu, 16 Jul 2020 01:20:05 +0100 [thread overview]
Message-ID: <ceb0567f-1422-4c68-29e2-6c72a5b67e02@jguk.org> (raw)
In-Reply-To: <9a03ca1c-d13d-519b-8d94-78ac7260f63d@gmail.com>
On 09/07/2020 17:15, Martin Sebor wrote:
> On 7/9/20 3:45 AM, Jonny Grant wrote:
>> Hello!
>>
>> There is an example below, (my code is not like this example below). I'm reporting a possible issue, and asking if there is a way to detect it in code bases. If it's a real issue I can file a bug report on Bugzilla.
>>
>> Can gcc warn where code will not get to the 'return 3;' below?
>
> -Wduplicated-branches detects a related problem. It's implemented
> entirely in the front end and quite simplistic. It just looks at
> the chain of expressions controlling the if statements and compares
> them for equality. I think it could be enhanced with not too much
> effort to detect a subset of this problem as well by considering
> the operator as well as its operands.
>
> Here's the function that does the checking and issues the warning:
> https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/c-family/c-warn.c#l2491
>
> Martin
>
>>
>> Cheers, Jonny
>>
>>
>> int main(void)
>> {
>> const int i = 1;
>> if(1 == i)
>> {
>> return 1;
>> }
>> else if(1 != i)
>> {
>> return 2;
>> }
>> else
>> {
>> return 3;
>> }
>> }
>>
>
I've added a ticket
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96214
Cheers
Jonny
prev parent reply other threads:[~2020-07-16 0:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 9:45 Jonny Grant
2020-07-09 15:00 ` Xi Ruoyao
2020-07-09 15:15 ` Jonny Grant
[not found] ` <e20bf113efcb7fe3e533ac694aa4bd62519b3654.camel@mengyan1223.wang>
2020-07-09 15:46 ` Xi Ruoyao
2020-07-09 15:46 ` Xi Ruoyao
[not found] ` <6d61e32f-3d69-9ac9-0a7e-88daa154c578@jguk.org>
2020-07-10 8:20 ` Xi Ruoyao
2020-07-10 21:50 ` Jonny Grant
2020-07-09 16:15 ` Martin Sebor
2020-07-16 0:20 ` Jonny Grant [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=ceb0567f-1422-4c68-29e2-6c72a5b67e02@jguk.org \
--to=jg@jguk.org \
--cc=gcc-help@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).