Skip to content

Commit 4e080bd

Browse files
committed
Wrap PYBIND11_OVERLOAD_NAME and PYBIND11_OVERLOAD_PURE_NAME in do { ... } while (false), and resolve trailing semicolon
1 parent 7e0a4fb commit 4e080bd

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

include/pybind11/pybind11.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,16 +2158,20 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
21582158
}
21592159
\endrst */
21602160
#define PYBIND11_OVERLOAD_NAME(ret_type, cname, name, fn, ...) \
2161-
PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
2162-
return cname::fn(__VA_ARGS__)
2161+
do { \
2162+
PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
2163+
return cname::fn(__VA_ARGS__) \
2164+
} while (false)
21632165

21642166
/** \rst
21652167
Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERLOAD_NAME`, except that it
21662168
throws if no overload can be found.
21672169
\endrst */
21682170
#define PYBIND11_OVERLOAD_PURE_NAME(ret_type, cname, name, fn, ...) \
2169-
PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
2170-
pybind11::pybind11_fail("Tried to call pure virtual function \"" PYBIND11_STRINGIFY(cname) "::" name "\"");
2171+
do { \
2172+
PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
2173+
pybind11::pybind11_fail("Tried to call pure virtual function \"" PYBIND11_STRINGIFY(cname) "::" name "\""); \
2174+
} while (false)
21712175

21722176
/** \rst
21732177
Macro to populate the virtual method in the trampoline class. This macro tries to look up the method

0 commit comments

Comments
 (0)