Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ PYBIND11_WARNING_DISABLE_CLANG("-Wgnu-zero-variadic-macro-arguments")
# include <cxxabi.h>
#endif

#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606
# define PYBIND11_MAYBE_CONSTEXPR constexpr
#else
# define PYBIND11_MAYBE_CONSTEXPR
#endif

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

/* https://stackoverflow.com/questions/46798456/handling-gccs-noexcept-type-warning
Expand Down Expand Up @@ -3606,13 +3612,15 @@ function get_override(const T *this_ptr, const char *name) {
auto o = override(__VA_ARGS__); \
PYBIND11_WARNING_PUSH \
PYBIND11_WARNING_DISABLE_MSVC(4127) \
if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value \
if PYBIND11_MAYBE_CONSTEXPR ( \
pybind11::detail::cast_is_temporary_value_reference<ret_type>::value \
&& !pybind11::detail::is_same_ignoring_cvref<ret_type, PyObject *>::value) { \
static pybind11::detail::override_caster_t<ret_type> caster; \
return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
} else { \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the else here? The other if branch ends with a return, the else seems redundant.

I think it'd be slightly better to leave the code down here as-is, in part because the PYBIND11_WARNING_POP is then before the return below.

return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
} \
PYBIND11_WARNING_POP \
return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
} \
} while (false)

Expand Down
Loading