RFR: 8062808: Turn on the -Wreturn-type warning

Stefan Karlsson stefan.karlsson at oracle.com
Wed Nov 5 20:47:09 UTC 2014


On 2014-11-05 21:20, John Rose wrote:
> This is a good gain in robustness.  Like Coleen, I'm agreeably 
> surprised at the relatively small number of fixes needed.
>
> On Nov 5, 2014, at 11:56 AM, Stefan Karlsson 
> <stefan.karlsson at oracle.com <mailto:stefan.karlsson at oracle.com>> wrote:
>
>> ...
>> A benefit of using the noreturn annotation would be to be able to 
>> turn on -Wuninitialized and get away with constructs like this:
>> int a;
>> switch (v) {
>> case 1: a = x; break;
>> case 2: a = y; break;
>> default: ShouldNotReachHere();
>> }
>> use(a);
>>
>> I have a patch were I started testing this, but there are a number of 
>> places were the compiler doesn't manage to infer that all paths taken 
>> will initialize the variable and we have to change the code to make 
>> it easier for the compiler to understand it. This will probably help 
>> with the readability of the code, so that is probably not something 
>> negative.
>
> I think this is a reasonable goal, worth a follow-up bug.
>
> One concern:  The noreturn annotation might differ in effect from 
> compiler to compiler, making it difficult to have one (simple) source 
> base that pleases all the compilers.
>
> Here's a suggestion:  Define a macro along these lines:
>    #define AFTER_NORETURN(code) {ShouldNotReachHere();code;}
>
> Use it for your two "Mute compiler" lines.  For compilers which have 
> noreturn, define it this way:
>    #define AFTER_NORETURN(code) /*nothing*/

Thanks for the tip.

>
> Thanks for pursuing these cleanups.

Thanks.

StefanK

>
> — John
>



More information about the hotspot-dev mailing list