Avoid is_constructible recursion in OnceAction

Both OnceAction compatibility traits, IsDirectlyCompatible and
IsCompatibleAfterIgnoringArguments, check std::is_constructible before
is_callable_r.

On libc++ that order breaks. Evaluating
is_constructible<std::tuple<OnceAction&&>, ...> drives libc++'s tuple
constructor SFINAE, which calls back into OnceAction's converting
constructor and re-enters the conjunction while it is still incomplete.
GCC <= 8 (e.g. QNX 7.1's gcc 8.3) rejects this with:

    incomplete type ... used in nested name specifier

so EXPECT_CALL(m, f()).WillOnce(Return(...)) fails to compile. GCC >= 9
and every Clang accept the original order; libstdc++ is unaffected.

Swapping the two checks fixes it: is_callable_r is cheap and
non-recursive, so the conjunction short-circuits to false for the
non-callable tuple before is_constructible is instantiated.

Fixes #3947.
This commit is contained in:
Niclas Larsson 2026-06-04 19:45:38 +02:00
parent 7140cd416c
commit b7ced159db

View File

@ -427,21 +427,21 @@ class [[nodiscard]] OnceAction<Result(Args...)> final {
// via StdFunctionAdaptor.
template <typename Callable>
using IsDirectlyCompatible = internal::conjunction<
// It must be possible to capture the callable in StdFunctionAdaptor.
std::is_constructible<typename std::decay<Callable>::type, Callable>,
// The callable must be compatible with our signature.
internal::is_callable_r<Result, typename std::decay<Callable>::type,
Args...>>;
Args...>,
// It must be possible to capture the callable in StdFunctionAdaptor.
std::is_constructible<typename std::decay<Callable>::type, Callable>>;
// True iff we can use the given callable type via StdFunctionAdaptor once we
// ignore incoming arguments.
template <typename Callable>
using IsCompatibleAfterIgnoringArguments = internal::conjunction<
// It must be possible to capture the callable in a lambda.
std::is_constructible<typename std::decay<Callable>::type, Callable>,
// The callable must be invocable with zero arguments, returning something
// convertible to Result.
internal::is_callable_r<Result, typename std::decay<Callable>::type>>;
internal::is_callable_r<Result, typename std::decay<Callable>::type>,
// It must be possible to capture the callable in a lambda.
std::is_constructible<typename std::decay<Callable>::type, Callable>>;
public:
// Construct from a callable that is directly compatible with our mocked