@@ -91,6 +91,42 @@ class OPENVINO_API NotImplemented : public AssertFailure {
9191protected:
9292 explicit NotImplemented (const std::string& what_arg) : ov::AssertFailure(what_arg) {}
9393};
94+
95+ namespace detail {
96+
97+ template <class T >
98+ constexpr inline bool check_condition (T&& v) noexcept {
99+ return static_cast <bool >(std::forward<T>(v));
100+ }
101+
102+ template <std::size_t N>
103+ constexpr inline bool check_condition (const char (&)[N]) noexcept {
104+ static_assert (N == 0 ,
105+ " OPENVINO_ASSERT: string literal used as condition (always true). "
106+ " Did you mean to compare strings or check a pointer?" );
107+ return false ;
108+ }
109+
110+ template <std::size_t N>
111+ constexpr inline bool check_condition (const wchar_t (&)[N]) noexcept {
112+ static_assert (N == 0 , " OPENVINO_ASSERT: wide string literal used as condition (always true)." );
113+ return false ;
114+ }
115+
116+ template <std::size_t N>
117+ constexpr inline bool check_condition (const char16_t (&)[N]) noexcept {
118+ static_assert (N == 0 , " OPENVINO_ASSERT: UTF-16 string literal used as condition (always true)." );
119+ return false ;
120+ }
121+
122+ template <std::size_t N>
123+ constexpr inline bool check_condition (const char32_t (&)[N]) noexcept {
124+ static_assert (N == 0 , " OPENVINO_ASSERT: UTF-32 string literal used as condition (always true)." );
125+ return false ;
126+ }
127+
128+ } // namespace detail
129+
94130} // namespace ov
95131
96132//
@@ -157,7 +193,7 @@ class OPENVINO_API NotImplemented : public AssertFailure {
157193//
158194#define OPENVINO_ASSERT_HELPER2 (exc_class, ctx, check, ...) \
159195 do { \
160- if (!static_cast < bool > (check)) { \
196+ if (!:: ov::detail::check_condition (check)) { \
161197 ::std::ostringstream ss___; \
162198 ::ov::write_all_to_stream (ss___, __VA_ARGS__); \
163199 exc_class::create (__FILE__, __LINE__, (#check), (ctx), ss___.str ()); \
@@ -166,7 +202,7 @@ class OPENVINO_API NotImplemented : public AssertFailure {
166202
167203#define OPENVINO_ASSERT_HELPER1 (exc_class, ctx, check ) \
168204 do { \
169- if (!static_cast < bool > (check)) { \
205+ if (!:: ov::detail::check_condition (check)) { \
170206 exc_class::create (__FILE__, __LINE__, (#check), (ctx), exc_class::default_msg); \
171207 } \
172208 } while (0 )
0 commit comments