r203029 - [-Wunreachable-code] generalize pruning out warning on trivial returns.

Ted Kremenek kremenek at apple.com
Wed Mar 5 16:25:54 PST 2014


On Mar 5, 2014, at 4:15 PM, David Blaikie <dblaikie at gmail.com> wrote:

>> +MyEnum trivial_dead_return_enum_2(int x) {
>> +  switch (x) {
>> +    case 1: return 1;
>> +    case 2: return 2;
>> +    case 3: return 3;
>> +  }
>> +
>> +  return 2; // no-warning
> 
> Wow - was this return really considered 'dead' at some point? How/why?
> That looks totally reachable...
> 
>> +}
>> +
>> +MyEnum nontrivial_dead_return_enum_2(int x) {
>> +  switch (x) {
>> +    case 1: return 1;
>> +    case 2: return 2;
>> +    case 3: return 3;
>> +    default: return 4;
>> +  }
>> +
>> +  return calledFun(); // expected-warning {{will never be executed}}
> 
> Did this not warn previously?

These two test cases are meant to be the same other than the return value in the second case is “non-trivial”, and thus we should warn.  The first test is missing the “default” case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140305/d0795a73/attachment.html>


More information about the cfe-commits mailing list