From ac28fad6f37f007cb36c92daff7492a31e5c68b3 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Fri, 23 Jun 2017 16:59:36 -0700 Subject: [PATCH] Add type assertion in Variable::Get --- paddle/framework/variable.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/paddle/framework/variable.h b/paddle/framework/variable.h index b21c95a1a6..b33e10e682 100644 --- a/paddle/framework/variable.h +++ b/paddle/framework/variable.h @@ -16,6 +16,8 @@ #include #include +#include "paddle/platform/assert.h" + namespace paddle { namespace framework { @@ -23,6 +25,9 @@ class Variable { public: template const T& Get() const { + PADDLE_ASSERT(holder_ != nullptr); + PADDLE_ASSERT(std::type_index(typeid(T)) == + std::type_index(holder_->Type())); return *static_cast(holder_->Ptr()); } -- GitLab