Skip to content

Commit 9a29637

Browse files
authored
More systematic gcc & clang coverage (#4083)
* More systematic gcc coverage, based on #4074 (comment) * Fix complete fail. * Resolve GCC 11 & 12 "redundant move in return statement" warnings. * Also add clang 11, 12, 13 (to gather info for warning suppressions). * Add & use `PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING`
1 parent cb35a3c commit 9a29637

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ jobs:
281281
std: 20
282282
- clang: 10
283283
std: 17
284+
- clang: 11
285+
std: 20
286+
- clang: 12
287+
std: 20
288+
- clang: 13
289+
std: 20
284290
- clang: 14
285291
std: 20
286292

@@ -437,14 +443,14 @@ jobs:
437443
strategy:
438444
fail-fast: false
439445
matrix:
440-
gcc:
441-
- 7
442-
- latest
443-
std:
444-
- 11
445446
include:
446-
- gcc: 10
447-
std: 20
447+
- { gcc: 7, std: 11 }
448+
- { gcc: 7, std: 17 }
449+
- { gcc: 8, std: 14 }
450+
- { gcc: 8, std: 17 }
451+
- { gcc: 10, std: 17 }
452+
- { gcc: 11, std: 20 }
453+
- { gcc: 12, std: 20 }
448454

449455
name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }}• x64"
450456
container: "gcc:${{ matrix.gcc }}"

include/pybind11/detail/common.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,24 @@ constexpr inline bool silence_msvc_c4127(bool cond) { return cond; }
11581158
# define PYBIND11_SILENCE_MSVC_C4127(...) __VA_ARGS__
11591159
#endif
11601160

1161+
#if defined(__clang__) \
1162+
&& (defined(__apple_build_version__) /* AppleClang 13.0.0.13000029 was the only data point \
1163+
available. */ \
1164+
|| (__clang_major__ >= 7 \
1165+
&& __clang_major__ <= 12) /* Clang 3, 5, 13, 14, 15 do not generate the warning. */ \
1166+
)
1167+
# define PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
1168+
// Example:
1169+
// tests/test_kwargs_and_defaults.cpp:46:68: error: local variable 'args' will be copied despite
1170+
// being returned by name [-Werror,-Wreturn-std-move]
1171+
// m.def("args_function", [](py::args args) -> py::tuple { return args; });
1172+
// ^~~~
1173+
// test_kwargs_and_defaults.cpp:46:68: note: call 'std::move' explicitly to avoid copying
1174+
// m.def("args_function", [](py::args args) -> py::tuple { return args; });
1175+
// ^~~~
1176+
// std::move(args)
1177+
#endif
1178+
11611179
// Pybind offers detailed error messages by default for all builts that are debug (through the
11621180
// negation of ndebug). This can also be manually enabled by users, for any builds, through
11631181
// defining PYBIND11_DETAILED_ERROR_MESSAGES.

include/pybind11/numpy.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,9 +1865,13 @@ struct vectorize_helper {
18651865
}
18661866

18671867
auto result = returned_array::create(trivial, shape);
1868+
#ifdef PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
1869+
# pragma clang diagnostic push
1870+
# pragma clang diagnostic ignored "-Wreturn-std-move"
1871+
#endif
18681872

18691873
if (size == 0) {
1870-
return std::move(result);
1874+
return result;
18711875
}
18721876

18731877
/* Call the function */
@@ -1878,7 +1882,10 @@ struct vectorize_helper {
18781882
apply_trivial(buffers, params, mutable_data, size, i_seq, vi_seq, bi_seq);
18791883
}
18801884

1881-
return std::move(result);
1885+
return result;
1886+
#ifdef PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
1887+
# pragma clang diagnostic pop
1888+
#endif
18821889
}
18831890

18841891
template <size_t... Index, size_t... VIndex, size_t... BIndex>

tests/test_kwargs_and_defaults.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
4343
m.def("kw_func_udl_z", kw_func, "x"_a, "y"_a = 0);
4444

4545
// test_args_and_kwargs
46-
m.def("args_function", [](py::args args) -> py::tuple { return std::move(args); });
46+
m.def("args_function", [](py::args args) -> py::tuple {
47+
#ifdef PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
48+
# pragma clang diagnostic push
49+
# pragma clang diagnostic ignored "-Wreturn-std-move"
50+
#endif
51+
return args;
52+
#ifdef PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
53+
# pragma clang diagnostic pop
54+
#endif
55+
});
4756
m.def("args_kwargs_function", [](const py::args &args, const py::kwargs &kwargs) {
4857
return py::make_tuple(args, kwargs);
4958
});

0 commit comments

Comments
 (0)