catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Add non-empty assertion to Option's deref op
- Commit
c6c46a168f5213d2daa4eccd6d725ced11229c49- Author
- Martin Hořeňovský ·
- Parents
48a889859bca
Changes
src/catch2/internal/catch_option.hpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/catch2/internal/catch_option.hpp b/src/catch2/internal/catch_option.hpp index 04e4d69e..da335653 100644 --- a/src/catch2/internal/catch_option.hpp +++ b/src/catch2/internal/catch_option.hpp @@ -46,10 +46,22 @@ namespace Catch { nullableValue = nullptr; } - T& operator*() { return *nullableValue; } - T const& operator*() const { return *nullableValue; } - T* operator->() { return nullableValue; } - const T* operator->() const { return nullableValue; } + T& operator*() { + assert(nullableValue); + return *nullableValue; + } + T const& operator*() const { + assert(nullableValue); + return *nullableValue; + } + T* operator->() { + assert(nullableValue); + return nullableValue; + } + const T* operator->() const { + assert(nullableValue); + return nullableValue; + } T valueOr( T const& defaultValue ) const { return nullableValue ? *nullableValue : defaultValue;