diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index 50fc1ed9f..5db59f6e6 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -46,21 +46,21 @@ struct ANTLR4CPP_PUBLIC Any template bool is() const { - auto derived = getDerived(); + auto derived = getDerived(false); return derived != nullptr; } template StorageType& as() { - auto derived = getDerived(); + auto derived = getDerived(true); return derived->value; } template const StorageType& as() const { - auto derived = getDerived(); + auto derived = getDerived(true); return derived->value; } @@ -143,12 +143,12 @@ private: } template - Derived>* getDerived() const { + Derived>* getDerived(bool checkCast) const { typedef StorageType T; auto derived = dynamic_cast*>(_ptr); - if (!derived) + if (checkCast && !derived) throw std::bad_cast(); return derived;