From c6c46a168f5213d2daa4eccd6d725ced11229c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 5 Oct 2021 19:22:22 +0200 Subject: [PATCH] Add non-empty assertion to Option's deref op --- 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;