Commit 40cc2e12 authored by Attila Krasznahorkay's avatar Attila Krasznahorkay
Browse files

Defined the StatusCode constant values explicitly.

This is needed to be able to use (for instance) constant references to these
constants in user code in C++14 mode. In C++17 mode the explicit declaration
is not needed anymore. But it also doesn't hurt the compilation.
parent 2d514f65
......@@ -11,6 +11,9 @@
// statics
bool StatusCode::s_checking( false );
constexpr const StatusCode::ErrorCode StatusCode::SUCCESS;
constexpr const StatusCode::ErrorCode StatusCode::FAILURE;
constexpr const StatusCode::ErrorCode StatusCode::RECOVERABLE;
namespace {
/// Default StatusCode category
......
......@@ -407,3 +407,22 @@ BOOST_AUTO_TEST_CASE( conversions ) {
// sc = 42; // no implicit conversion from int
// int i = sc; // no implicit conversion to int
}
/// Function used for testing that the constants in @c StatusCode can be found
/// by constant references.
bool __attribute__( ( noinline ) )
testReferencePassing( const StatusCode::ErrorCode& value,
const StatusCode::ErrorCode& reference ) {
return ( value == reference );
}
BOOST_AUTO_TEST_CASE( const_definitions ) {
// Test whether the test can compile/link correctly when passing the
// constants in @c StatusCode into a function by constant reference.
BOOST_CHECK( testReferencePassing( StatusCode::SUCCESS,
StatusCode::SUCCESS ) );
BOOST_CHECK( testReferencePassing( StatusCode::FAILURE,
StatusCode::FAILURE ) );
BOOST_CHECK( testReferencePassing( StatusCode::RECOVERABLE,
StatusCode::RECOVERABLE ) );
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment