Re: gcc warn unreached else {}

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

 



On 2020-07-09 10:45 +0100, 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?
> 
> Cheers, Jonny
> 
> 
> int main(void)
> {
>     const int i = 1;
>     if(1 == i)
>     {
>         return 1;
>     }
>     else if(1 != i)
>     {
>         return 2;
>     }
>     else
>     {
>         return 3;
>     }
> }

Generally finding all the branches in a program impossible to be executed is
unsolvable.  Even in a program without any loop it's still NP-hard.

For some "simple" cases maybe we can implement some heuristics, or use a brute
force approach (as a part of -fanalyzer).  But I doubt if these simple cases are
really useful.
-- 
Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[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