@@ -2141,7 +2141,8 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
21412141 return tinfo ? get_type_overload (this_ptr, tinfo, name) : function ();
21422142}
21432143
2144- #define PYBIND11_OVERLOAD_INT (ret_type, cname, name, ...) { \
2144+ #define PYBIND11_OVERLOAD_INT (ret_type, cname, name, ...) \
2145+ do { \
21452146 pybind11::gil_scoped_acquire gil; \
21462147 pybind11::function overload = pybind11::get_overload (static_cast <const cname *>(this ), name); \
21472148 if (overload) { \
@@ -2152,7 +2153,7 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
21522153 } \
21532154 else return pybind11::detail::cast_safe<ret_type>(std::move (o)); \
21542155 } \
2155- }
2156+ } while ( false )
21562157
21572158/* * \rst
21582159 Macro to populate the virtual method in the trampoline class. This macro tries to look up a method named 'fn'
@@ -2172,16 +2173,20 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
21722173 }
21732174\endrst */
21742175#define PYBIND11_OVERLOAD_NAME (ret_type, cname, name, fn, ...) \
2175- PYBIND11_OVERLOAD_INT (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), name, __VA_ARGS__) \
2176- return cname::fn (__VA_ARGS__)
2176+ do { \
2177+ PYBIND11_OVERLOAD_INT (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), name, __VA_ARGS__); \
2178+ return cname::fn (__VA_ARGS__); \
2179+ } while (false )
21772180
21782181/* * \rst
21792182 Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERLOAD_NAME`, except that it
21802183 throws if no overload can be found.
21812184\endrst */
21822185#define PYBIND11_OVERLOAD_PURE_NAME (ret_type, cname, name, fn, ...) \
2183- PYBIND11_OVERLOAD_INT (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), name, __VA_ARGS__) \
2184- pybind11::pybind11_fail (" Tried to call pure virtual function \" " PYBIND11_STRINGIFY (cname) " ::" name " \" " );
2186+ do { \
2187+ PYBIND11_OVERLOAD_INT (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), name, __VA_ARGS__); \
2188+ pybind11::pybind11_fail (" Tried to call pure virtual function \" " PYBIND11_STRINGIFY (cname) " ::" name " \" " ); \
2189+ } while (false )
21852190
21862191/* * \rst
21872192 Macro to populate the virtual method in the trampoline class. This macro tries to look up the method
0 commit comments