From e02f67eff704648b31de86efeef4f620c3af03a1 Mon Sep 17 00:00:00 2001 From: sneaxiy Date: Mon, 24 Dec 2018 10:02:08 +0000 Subject: [PATCH] rewrite unsafe_cast test=develop --- paddle/fluid/framework/ddim.cc | 4 ---- paddle/fluid/framework/ddim.h | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/ddim.cc b/paddle/fluid/framework/ddim.cc index 37544e97eb..e7a6df57e5 100644 --- a/paddle/fluid/framework/ddim.cc +++ b/paddle/fluid/framework/ddim.cc @@ -131,8 +131,6 @@ DDim slice_ddim(const DDim& dim, int begin, int end) { int arity(const DDim& d) { return d.size(); } -/// \cond HIDDEN - struct DDimPrinter { std::ostream& os; explicit DDimPrinter(std::ostream& os_) : os(os_) {} @@ -143,8 +141,6 @@ struct DDimPrinter { } }; -/// \endcond - std::ostream& operator<<(std::ostream& os, const DDim& ddim) { ddim.apply_visitor(DDimPrinter(os)); return os; diff --git a/paddle/fluid/framework/ddim.h b/paddle/fluid/framework/ddim.h index 452072a587..295d09bbca 100644 --- a/paddle/fluid/framework/ddim.h +++ b/paddle/fluid/framework/ddim.h @@ -126,7 +126,9 @@ class DDim { private: template inline Dim& UnsafeCast() { - return const_cast&>(const_cast(this)->UnsafeCast()); + static_assert(D >= 0 && D <= kMaxRank, "Invalid rank"); + auto* p = static_cast(&dim_); + return *reinterpret_cast*>(p); } template -- GitLab