Avoid LNK2001 in c++20 when /GL (Whole program optimization) is ON with MSVC#5939
Avoid LNK2001 in c++20 when /GL (Whole program optimization) is ON with MSVC#5939rwgk merged 1 commit intopybind:masterfrom
Conversation
99ed4d1 to
74922f2
Compare
…th MSVC Update pybind11.h
| && !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 { \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
The else is added here because the CI checks complained “warning C4702: unreachable code”( in which case the constexpr if evals true, and the code outside that constexpr if becomes unreachable ). Since the CI checks turn on "warning as error", the CI checks will failed.
There was a problem hiding this comment.
Sorry for the late reply.
There was a problem hiding this comment.
Thanks for the explanation!
The warning will be annoying, seems like a second C4127, not keeping up with the times (templates), so I think we'll probably wind up suppressing C4702 as we make more use of constexpr in the future ... but your solution is good for now.
The following c++20 code would not link when using /GL in MSVC:
The error is:
We can use constexpr if to avoid this link error.