abort() is not __declspec(noreturn) in VS2010

半城伤御伤魂 提交于 2019-12-08 14:44:12

问题


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:


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/



来源:https://stackoverflow.com/questions/3569643/abort-is-not-declspecnoreturn-in-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!