Skip to content

Commit 137f67e

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
gmock: improve SFINAE for actions involving arguments.
Avoid instantiating functions like std::get<index> for an out of range index when doing SFINAE on the invocability of the action itself. PiperOrigin-RevId: 439415110 Change-Id: Ifc20285a6d526c34830870cd1910c2b2b92e1e81
1 parent 3ffa237 commit 137f67e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

googlemock/include/gmock/gmock-actions.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,8 @@ struct ReturnNewAction {
10771077

10781078
template <size_t k>
10791079
struct ReturnArgAction {
1080-
template <typename... Args>
1080+
template <typename... Args,
1081+
typename = typename std::enable_if<(k < sizeof...(Args))>::type>
10811082
auto operator()(Args&&... args) const -> decltype(std::get<k>(
10821083
std::forward_as_tuple(std::forward<Args>(args)...))) {
10831084
return std::get<k>(std::forward_as_tuple(std::forward<Args>(args)...));

googlemock/include/gmock/gmock-more-actions.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
600600

601601
template <std::size_t index, typename... Params>
602602
struct InvokeArgumentAction {
603-
template <typename... Args>
603+
template <typename... Args,
604+
typename = typename std::enable_if<(index < sizeof...(Args))>::type>
604605
auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument(
605606
std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)),
606607
std::declval<const Params&>()...)) {

0 commit comments

Comments
 (0)