Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

noreturn

This __declspec attribute tells the compiler that a function does not return. As a consequence, the compiler knows that the code following a call to a __declspec(noreturn) function is unreachable.

If the compiler finds a function with a control path that does not return a value, it generates a warning (C4715) or error message (C2202). If the control path cannot be reached due to a function that never returns, you can use __declspec(noreturn) to prevent this warning or error.

NoteNote

Adding __declspec(noreturn) to a function that is expected to return can result in undefined behavior.

In the following sample,the else clause does not contain a return statement. Declaring fatal as __declspec(noreturn) avoids an error or warning message.

// noreturn2.cpp
__declspec(noreturn) extern void fatal () {}

int main() {
   if(1)
     return 1;
   else if(0)
     return 0;
   else
     fatal();
}

Community Additions

ADD
Show:
© 2015 Microsoft