Re: gcc warn unreached else {}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux