views:

153

answers:

1

In my copy of VS2010, stdlib.h contains (lines 353-355)

_CRTIMP __declspec(noreturn) void __cdecl exit(_In_ int _Code);
_CRTIMP __declspec(noreturn) void __cdecl _exit(_In_ int _Code);
_CRTIMP void __cdecl abort(void);

I find it strange that there's no noreturn annotation on abort(). Does anyone know a reason for this? Is it a bug?

EDIT: In VS2008, it's the same, but lines 371-373 of stdlib.h

The lack of the noreturn annotation is triggering error C4716.

Further reference: C++0x proposal for standardization of the noreturn annotation, which says that abort should carry it.

EDIT: Looks like a bunch of discussion disappeared with a deleted answer, but the gist of it is covered in Defect Report #048.

+1  A: 

I think this is definitely wrong because regardless of what the std mandates, the abort() implementation shipped with Visual Studio will never return from abort. You cannot do anything in the signal handler for SIGABRT that will prevent _exit(3) being called at the end of the abort() implementation of Visual Studio (I'm looking at the file abort.c, line 137 in the sources shipped with VS 2005).

So since __declspec(noreturn) is an implementation thing and since the implemenation of abort in Visual Studio will never, ever return normally, abort() should be tagged with __declspec(noreturn).

It follows that it's absence is a bug.

I think you should report this as a bug at https://connect.microsoft.com/VisualStudio/

Martin
What part of the standard do you think would ever allow a conforming implementation to return from `abort()`? AFAICT `SIGABRT` cannot be ignored. POSIX makes some mention of "if the signal handler never returns" which suggests that abort could be cancelled by `longjmp` (or the equivalent implemented with C++ exceptions) but not via return.
Ben Voigt
I do not know what part of the std would or would not and I think it does not matter what the std says. The abort() implementation of MS will never return. Therefore it is an implementation bug that it is not tagged noreturn.
Martin