Skip to content

Commit 6153d21

Browse files
committed
[libc++] Fix std::variant/std::invoke too eager instantiation
1 parent cdb67e1 commit 6153d21

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

libcxx/include/__type_traits/invoke.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <__type_traits/is_same.h>
2323
#include <__type_traits/is_void.h>
2424
#include <__type_traits/nat.h>
25+
#include <__type_traits/type_identity.h>
2526
#include <__type_traits/void_t.h>
2627
#include <__utility/declval.h>
2728
#include <__utility/forward.h>
@@ -67,20 +68,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6768

6869
#if __has_builtin(__builtin_invoke)
6970

70-
template <class... _Args>
71-
using __invoke_result_t _LIBCPP_NODEBUG = decltype(__builtin_invoke(std::declval<_Args>()...));
72-
7371
template <class, class... _Args>
7472
struct __invoke_result_impl {};
7573

7674
template <class... _Args>
77-
struct __invoke_result_impl<__void_t<__invoke_result_t<_Args...> >, _Args...> {
78-
using type _LIBCPP_NODEBUG = __invoke_result_t<_Args...>;
75+
struct __invoke_result_impl<__void_t<decltype(__builtin_invoke(std::declval<_Args...>()))>, _Args...> {
76+
using type _LIBCPP_NODEBUG = decltype(__builtin_invoke(std::declval<_Args...>()));
7977
};
8078

8179
template <class... _Args>
8280
using __invoke_result _LIBCPP_NODEBUG = __invoke_result_impl<void, _Args...>;
8381

82+
template <class... _Args>
83+
using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Args...>::type;
84+
8485
template <class... _Args>
8586
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __invoke_result_t<_Args...> __invoke(_Args&&... __args)
8687
_NOEXCEPT_(noexcept(__builtin_invoke(std::forward<_Args>(__args)...))) {

libcxx/test/std/test.pass.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <variant>
10+
#include <utility>
11+
12+
struct Nullable {
13+
template <typename V> Nullable(V);
14+
};
15+
16+
struct Matcher {
17+
Matcher();
18+
Matcher(std::variant<Nullable>);
19+
};
20+
21+
void f() {
22+
Matcher vec;
23+
Matcher m = std::move(vec);
24+
}

0 commit comments

Comments
 (0)