Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
#include "TeuchosCore_config.h"
Go to the source code of this file.
Macros | |
#define | TEUCHOS_UNREACHABLE_RETURN_IMPL(dummyReturnVal) return dummyReturnVal |
#define | TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal) TEUCHOS_UNREACHABLE_RETURN_IMPL(dummyReturnVal) |
Avoid warning about unreachable or missing return from function. More... | |
#define TEUCHOS_UNREACHABLE_RETURN_IMPL | ( | dummyReturnVal | ) | return dummyReturnVal |
Definition at line 24 of file Teuchos_CompilerCodeTweakMacros.hpp.
#define TEUCHOS_UNREACHABLE_RETURN | ( | dummyReturnVal | ) | TEUCHOS_UNREACHABLE_RETURN_IMPL(dummyReturnVal) |
Avoid warning about unreachable or missing return from function.
Consider a function like:
That code will never execute out of the switch statement. However, some compilers will provide a warning that the function may not return a value. Therefore, one can remove this warning by adding a dummy return value like:
That removes the "may not return value" warning on those compilers. But other compilers will correctly warn that return -1;
will never be executed with a warning like "statement is unreachable". Therefore, to address warnings like this, this macro is used like:
On compilers that warn about the return being unreachable the return statement is skipped. On every other compiler, the return statement is kept which results in safer code under refactoring (by avoiding undefined behavior when returning from a function by fall-through without returning an explicit value.
Definition at line 99 of file Teuchos_CompilerCodeTweakMacros.hpp.