mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Removing GCC -Wunused-but-set-parameter from pragma block at the top of pybind11.h (#3164)
* Cleanup triggered by work on pragma for GCC -Wunused-but-set-parameter. * Backing out changes to eigen.h (to be worked on later). * Adding PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER in type_caster_base.h (apparently needed only for older GCCs). * Apparently older compilers need a simpler overload for silence_unused_warnings(). * clang C++11 compatibility: removing constexpr * Special case for MSVC 2017: `constexpr void` return * Trying again without the silence_unused_warnings(const int *) overload. * Separate macros for ALL_GCC, OLD_GCC_UNUSED_BUT_SET_PARAMETER * Changing to __GNUC__ <= 2 (turning off) * Refined condition for PYBIND11_WORKAROUND_INCORRECT_OLD_GCC_UNUSED_BUT_SET_PARAMETER. * Quick experiment trying out suggestion by @henryiii * Introducing macro: PYBIND11_INT_ARRAY_WORKING_AROUND_MSVC_CLANG_ISSUES * Trying henryiii@ (void) expander idea. * fix: apply simpler expression with fewer workarounds * Purging new-but-already-obsoleted macro, made possible by @henryiii's commit. * Renaming `ALL_GCC` macro back to just `GCC` (because there is no `OLD` anymore, luckily). * [actions skip] Adding "All GCC versions" to comment, to be clear about it. Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
parent
3893f37bce
commit
af7007331a
@ -517,23 +517,30 @@ template <size_t Nurse, size_t Patient> struct process_attribute<keep_alive<Nurs
|
||||
template <typename... Args> struct process_attributes {
|
||||
static void init(const Args&... args, function_record *r) {
|
||||
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
|
||||
int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
|
||||
ignore_unused(unused);
|
||||
PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r);
|
||||
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);
|
||||
int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
|
||||
ignore_unused(unused);
|
||||
PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r);
|
||||
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);
|
||||
int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::precall(call), 0) ... };
|
||||
ignore_unused(unused);
|
||||
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);
|
||||
int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0) ... };
|
||||
ignore_unused(unused);
|
||||
PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(fn_ret);
|
||||
using expander = int[];
|
||||
(void) expander{
|
||||
0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0)...};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -609,6 +609,7 @@ protected:
|
||||
template <typename T, size_t... Is>
|
||||
static handle cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence<Is...>) {
|
||||
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(src, policy, parent);
|
||||
PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(policy, parent);
|
||||
std::array<object, size> entries{{
|
||||
reinterpret_steal<object>(make_caster<Ts>::cast(std::get<Is>(std::forward<T>(src)), policy, parent))...
|
||||
}};
|
||||
@ -1235,8 +1236,8 @@ public:
|
||||
// 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();
|
||||
int _[] = { 0, (process(args_list, std::forward<Ts>(values)), 0)... };
|
||||
ignore_unused(_);
|
||||
using expander = int[];
|
||||
(void) expander{0, (process(args_list, std::forward<Ts>(values)), 0)...};
|
||||
|
||||
m_args = std::move(args_list);
|
||||
}
|
||||
|
@ -734,9 +734,6 @@ using function_signature_t = conditional_t<
|
||||
template <typename T> using is_lambda = satisfies_none_of<remove_reference_t<T>,
|
||||
std::is_function, std::is_pointer, std::is_member_pointer>;
|
||||
|
||||
/// Ignore that a variable is unused in compiler warnings
|
||||
inline void ignore_unused(const int *) { }
|
||||
|
||||
// [workaround(intel)] Internal error on fold expression
|
||||
/// Apply a function over each element of a parameter pack
|
||||
#if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
|
||||
@ -927,19 +924,29 @@ inline static std::shared_ptr<T> try_get_shared_from_this(std::enable_shared_fro
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1916
|
||||
|
||||
// warning C4100: Unreferenced formal parameter
|
||||
// For silencing "unused" compiler warnings in special situations.
|
||||
template <typename... Args>
|
||||
inline constexpr void workaround_incorrect_msvc_c4100(Args &&...) {}
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER < 1920 // MSVC 2017
|
||||
constexpr
|
||||
#endif
|
||||
inline void silence_unused_warnings(Args &&...) {}
|
||||
|
||||
// MSVC warning C4100: Unreferenced formal parameter
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1916
|
||||
# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) \
|
||||
detail::workaround_incorrect_msvc_c4100(__VA_ARGS__)
|
||||
|
||||
detail::silence_unused_warnings(__VA_ARGS__)
|
||||
#else
|
||||
# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
|
||||
#endif
|
||||
|
||||
// GCC -Wunused-but-set-parameter All GCC versions (as of July 2021).
|
||||
#if defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
|
||||
# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...) \
|
||||
detail::silence_unused_warnings(__VA_ARGS__)
|
||||
#else
|
||||
# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) // All versions (as of July 2021).
|
||||
|
||||
// warning C4127: Conditional expression is constant
|
||||
|
@ -927,18 +927,17 @@ protected:
|
||||
using Constructor = void *(*)(const void *);
|
||||
|
||||
/* Only enabled when the types are {copy,move}-constructible *and* when the type
|
||||
does not have a private operator new implementation. */
|
||||
does not have a private operator new implementation. A comma operator is used in the decltype
|
||||
argument to apply SFINAE to the public copy/move constructors.*/
|
||||
template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
|
||||
static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) {
|
||||
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x);
|
||||
static auto make_copy_constructor(const T *) -> decltype(new T(std::declval<const T>()), Constructor{}) {
|
||||
return [](const void *arg) -> void * {
|
||||
return new T(*reinterpret_cast<const T *>(arg));
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T, typename = enable_if_t<std::is_move_constructible<T>::value>>
|
||||
static auto make_move_constructor(const T *x) -> decltype(new T(std::move(*const_cast<T *>(x))), Constructor{}) {
|
||||
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x);
|
||||
static auto make_move_constructor(const T *) -> decltype(new T(std::declval<T&&>()), Constructor{}) {
|
||||
return [](const void *arg) -> void * {
|
||||
return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
|
||||
};
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#if defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
|
||||
# pragma GCC diagnostic ignored "-Wattributes"
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user