Export (0) Print
Expand All
Expand Minimize
2 out of 10 rated this helpful - Rate this topic

Compiler Warning (level 4) C4702

Error Message

unreachable code

This warning is the result of compiler conformance work that was done for Visual Studio .NET 2003: unreachable code. When the compiler (back end) detects unreachable code, it will generate C4702, a level 4 warning.

For code that is valid in both the Visual Studio .NET 2003 and Visual Studio .NET versions of Visual C++, remove the unreachable code or assure that all source code is reachable by some flow of execution.

See Summary of Compiler-Time Breaking Changes for more information.


The following sample generates C4702.

// C4702.cpp
// compile with: /W4
#include <stdio.h>

int main() {
   return 1;
   printf_s("I won't print.\n");   // C4702 unreachable

When compiling with /GX, /EHc, /EHsc, or /EHac and using extern C functions, code can become unreachable because extern C functions are assumed to not throw, thus the catch block isn't reachable. If you feel that this warning is not valid because a function can throw, compile with /EHa or /EHs, depending on the exception thrown.

For more information, see /EH (Exception Handling Model) for more information.

The following sample generates C4702.

// C4702b.cpp
// compile with: /W4 /EHsc
#include <iostream>

using namespace std;
extern "C" __declspec(dllexport) void Function2(){}

int main() {
   try {
   catch (...) {
      cout << "Exp: Function2!" << endl;   // C4702
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.