Skip to content

Commit

Permalink
Trying henryiii@ (void) expander idea.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 4, 2021
1 parent a5c8f3f commit c24c892
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
21 changes: 12 additions & 9 deletions include/pybind11/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,26 +518,29 @@ template <typename... Args> struct process_attributes {
static void init(const Args&... args, function_record *r) {
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
PYBIND11_WORKAROUND_INCORRECT_ALL_GCC_UNUSED_BUT_SET_PARAMETER(r);
PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(
{0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...});
using expander = int[];
(void) expander{
0, ((void) process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...};
}
static void init(const Args&... args, type_record *r) {
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
PYBIND11_WORKAROUND_INCORRECT_ALL_GCC_UNUSED_BUT_SET_PARAMETER(r);
PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(
{0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...});
using expander = int[];
(void) expander{0,
(process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...};
}
static void precall(function_call &call) {
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call);
PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(
{0, (process_attribute<typename std::decay<Args>::type>::precall(call), 0)...});
using expander = int[];
(void) expander{0,
(process_attribute<typename std::decay<Args>::type>::precall(call), 0)...};
}
static void postcall(function_call &call, handle fn_ret) {
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call, fn_ret);
PYBIND11_WORKAROUND_INCORRECT_ALL_GCC_UNUSED_BUT_SET_PARAMETER(fn_ret);
PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(
{0,
(process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0)...});
using expander = int[];
(void) expander{
0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0)...};
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,8 @@ class unpacking_collector {
// Tuples aren't (easily) resizable so a list is needed for collection,
// but the actual function call strictly requires a tuple.
auto args_list = list();
PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(
{0, (process(args_list, std::forward<Ts>(values)), 0)...});
using expander = int[];
(void) expander{0, (process(args_list, std::forward<Ts>(values)), 0)...};

m_args = std::move(args_list);
}
Expand Down
11 changes: 0 additions & 11 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,17 +955,6 @@ inline void silence_unused_warnings(Args &&...) {}
# define PYBIND11_WORKAROUND_INCORRECT_OLD_GCC_UNUSED_BUT_SET_PARAMETER(...)
#endif

// MSVC error C4576: a parenthesized type followed by an initializer list is a
// non-standard explicit type conversion syntax
// clang: expression result unused [-Wunused-value]
#if defined(_MSC_VER) || defined(__clang__) // All versions (as of July 2021).
# define PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(...) \
int dummy[] = __VA_ARGS__; \
detail::silence_unused_warnings(dummy)
#else
# define PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES(...) (int[]) __VA_ARGS__
#endif

#if defined(_MSC_VER) // All versions (as of July 2021).

// warning C4127: Conditional expression is constant
Expand Down

0 comments on commit c24c892

Please sign in to comment.