diff options
author | Abseil Team <absl-team@google.com> | 2022-04-04 21:38:08 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-04-04 21:38:58 (GMT) |
commit | 137f67e91fb78f15b5407a27e94d9dded8df818c (patch) | |
tree | 798bd970ad4ebc7498f27278e4b17e2bf1fdc884 | |
parent | 3ffa237f0ed258bf92b28ab00dce3ecda84efffe (diff) | |
download | googletest-137f67e91fb78f15b5407a27e94d9dded8df818c.zip googletest-137f67e91fb78f15b5407a27e94d9dded8df818c.tar.gz googletest-137f67e91fb78f15b5407a27e94d9dded8df818c.tar.bz2 |
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
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 3 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-more-actions.h | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 26272e9..2c4ce36 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1077,7 +1077,8 @@ struct ReturnNewAction { template <size_t k> struct ReturnArgAction { - template <typename... Args> + template <typename... Args, + typename = typename std::enable_if<(k < sizeof...(Args))>::type> auto operator()(Args&&... args) const -> decltype(std::get<k>( std::forward_as_tuple(std::forward<Args>(args)...))) { return std::get<k>(std::forward_as_tuple(std::forward<Args>(args)...)); diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index 87307f0..148ac01 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -600,7 +600,8 @@ auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) { template <std::size_t index, typename... Params> struct InvokeArgumentAction { - template <typename... Args> + template <typename... Args, + typename = typename std::enable_if<(index < sizeof...(Args))>::type> auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument( std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)), std::declval<const Params&>()...)) { |