Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros
Teuchos_CompilerCodeTweakMacros.hpp File Reference
#include "TeuchosCore_config.h"
Include dependency graph for Teuchos_CompilerCodeTweakMacros.hpp:
This graph shows which files directly or indirectly include this file:

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...
 

Macro Definition Documentation

#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:

int func(const ESomeEnum val)
{
switch (val) {
case VAL1: return 1;
case VAL2: return 2;
default: TEUCHOS_TEST_FOR_EXCEPT(true);
}
}

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:

int func(const ESomeEnum val)
{
switch (val) {
case VAL1: return 1;
case VAL2: return 2;
default: TEUCHOS_TEST_FOR_EXCEPT(true);
}
return -1; // Will never get called!
}

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:

int func(const ESomeEnum val)
{
switch (val) {
case VAL1: return 1;
case VAL2: return 2;
default: TEUCHOS_TEST_FOR_EXCEPT(true);
}
}

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.