diff --git a/src/exception.cc b/src/exception.cc index 020eafec5229463f8959866b7c6e6e163e1ed68b..15cf0a50cff2c84f1fbed97b18f6972dfe10ff6c 100644 --- a/src/exception.cc +++ b/src/exception.cc @@ -80,7 +80,7 @@ Exception::~Exception() Exception::Exception(const struct type *type_arg, const char *file, unsigned line) :type(type_arg), m_ref(0) { - if (m_file != NULL) { + if (file != NULL) { snprintf(m_file, sizeof(m_file), "%s", file); m_line = line; } else { diff --git a/src/lua/utils.cc b/src/lua/utils.cc index e89ef600ad106486e5f2124d5d3201e9fee53717..9c61376e58cd1e8a966abd1b72b3c7951a735b31 100644 --- a/src/lua/utils.cc +++ b/src/lua/utils.cc @@ -100,6 +100,7 @@ int luaL_cdef(struct lua_State *L, const char *what) { int idx = lua_gettop(L); + (void) idx; /* This function calls ffi.cdef */ /* Get ffi.typeof function */ diff --git a/src/reflection.h b/src/reflection.h index 669b66b2b28d01b8c2abc19d42bb6afe72cbff42..746a70fdd6fab954ab8bd12b34b367ee2463d710 100644 --- a/src/reflection.h +++ b/src/reflection.h @@ -100,8 +100,6 @@ struct method { void *_spacer[2]; #if defined(__cplusplus) method_thiscall_f thiscall; - static_assert(sizeof(thiscall) <= sizeof(_spacer), - "sizeof(thiscall)"); #endif /* defined(__cplusplus) */ }; }; @@ -126,6 +124,9 @@ extern const struct method METHODS_SENTINEL; #if defined(__cplusplus) } /* extern "C" */ +static_assert(sizeof(((struct method *) 0)->thiscall) <= + sizeof(((struct method *) 0)->_spacer), "sizeof(thiscall)"); + /* * Begin of C++ syntax sugar */ @@ -250,6 +251,14 @@ method_invokable(const struct method *method, T *object) return method_helper<0, Args...>::invokable(method); } +template<typename R, typename... Args, typename T> inline bool +method_invokable(const struct method *method, const T *object) +{ + if (!method->isconst) + return false; + return method_invokable<R, Args...>(method, const_cast<T*>(object)); +} + /** * Invoke method with object and provided arguments. */ @@ -261,13 +270,6 @@ method_invoke(const struct method *method, T *object, Args... args) return (object->*(MemberFunction) method->thiscall)(args...); } -template<typename R, typename... Args, typename T > inline R -method_invoke(const struct method *method, const T *object, Args... args) -{ - assert(method->isconst); - return method_invoke<R, Args...>(object, args...); -} - #endif /* defined(__cplusplus) */ #endif /* TARANTOOL_REFLECTION_H_INCLUDED */ diff --git a/test/unit/reflection_cxx.cc b/test/unit/reflection_cxx.cc index ee100a77dce9ef22a632990ce58fb73f78c981e3..6369fd0b300094781d9921f0bcf6b58dacae042a 100644 --- a/test/unit/reflection_cxx.cc +++ b/test/unit/reflection_cxx.cc @@ -84,7 +84,7 @@ const struct type type_Tarantool = make_type("Tarantool", &type_Database, int main() { - plan(29); + plan(30); Object obj; Tarantool tntobj; @@ -170,5 +170,9 @@ main() iret = method_invoke<int>(get_int, &tntobj); is(iret, 49, "invoke (void)"); + const Tarantool *tntconstptr = &tntobj; + ok((!method_invokable<void, const char *>(put_string, tntconstptr)), + "!invokable<>() on const method with non-const object"); + return check_plan(); } diff --git a/test/unit/reflection_cxx.result b/test/unit/reflection_cxx.result index 92a545939124dee713f57514d1d2325f21868562..0f4f51eb44dd8fbf89c7ad74706126bdf0570bfd 100644 --- a/test/unit/reflection_cxx.result +++ b/test/unit/reflection_cxx.result @@ -1,4 +1,4 @@ -1..29 +1..30 ok 1 - type.name ok 2 - type.parent ok 3 - type.parent @@ -28,3 +28,4 @@ ok 26 - invokable<void, const char *> ok 27 - invoke (int) ok 28 - invoke (const char *) ok 29 - invoke (void) +ok 30 - !invokable<>() on const method with non-const object