Re: [PATCH 2/2] remove NORETURN from function pointers
- From
Johannes Sixt <j.sixt@viscovery.net>
- Date
- Sep 14, 2009, 13:19 UTC
- Message-ID
- <4AAE42F2.30304@viscovery.net>
- In-Reply-To
- <40aa078e0909140612w71ad3bdeyfa94838cb57cec19@mail.gmail.com>
Erik Faye-Lund schrieb:
Show 24 quoted lines
> On Mon, Sep 14, 2009 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>> Erik Faye-Lund schrieb:
>>> Compiling the following code gives a warning about unreachable code,
>>> so it's clear that msvc doesn't simply ignore the directive. I'm not
>>> saying that anyone suggested otherwise, I just wanted to know for
>>> sure.
>>>
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>> void (*exit_fun)(int) = exit;
>>> void __declspec(noreturn) die(void);
>>> void die(void) { exit_fun(1); }
>>> int main(void) { printf("hello!\n"); die(); printf("world!\n"); }
>> In order to countermand any clever optimizations you should make it
>>
>> -void (*exit_fun)(int) = exit;
>> +extern void (*exit_fun)(int);
>>
>> (of course, this fails to link). But if this results in only *one* warning
>> (that the printf() call is unreachable), then I wouldn't bother with this
>> problem anymore, because you really should also have been warned that a
>> __declspec(noreturn) function actually does return.
>
> Ah, good point. Still gives the warning (as well as the linker-error), though."The" warning? Not "the two" warnings? Then I suggest to stop here; MSVC is only half-competent with regards to noreturn.
-- Hannes