[libcxx-commits] [libcxx] 73e8e1b - [libc++][NFC] Qualify declval
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jan 12 09:28:47 PST 2023
Author: Nikolas Klauser
Date: 2023-01-12T18:28:41+01:00
New Revision: 73e8e1ba8daddae1e0f5a013025596e6ff2a0101
URL: https://github.com/llvm/llvm-project/commit/73e8e1ba8daddae1e0f5a013025596e6ff2a0101
DIFF: https://github.com/llvm/llvm-project/commit/73e8e1ba8daddae1e0f5a013025596e6ff2a0101.diff
LOG: [libc++][NFC] Qualify declval
While it's not necessary to qualify calls to `declval` it makes error messages very crypric if the declaration isn't reachable anymore
For example:
```
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:53:66: error: no type named 'type' in 'std::common_type<long, long>'
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:107:14: note: in instantiation of template class 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>, std::chrono::duration<long, std::ratio<3600, 1>>>' requested here
: public common_type<_Tp, _Tp> {};
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:279:58: note: in instantiation of template class 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>>' requested here
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:308:54: note: in instantiation of template class 'std::chrono::duration<long, std::ratio<3600, 1>>' requested here
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:280:81: error: no type named 'type' in 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>>'
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:308:54: note: in instantiation of template class 'std::chrono::duration<long, std::ratio<3600, 1>>' requested here
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:53:66: error: no type named 'type' in 'std::common_type<int, int>'
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:107:14: note: in instantiation of template class 'std::common_type<std::chrono::duration<int, std::ratio<86400, 1>>, std::chrono::duration<int, std::ratio<86400, 1>>>' requested here
: public common_type<_Tp, _Tp> {};
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:279:58: note: in instantiation of template class 'std::common_type<std::chrono::duration<int, std::ratio<86400, 1>>>' requested here
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:309:55: note: in instantiation of template class 'std::chrono::duration<int, std::ratio<86400, 1>>' requested here
typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
^
19 similar errors omitted
```
changes with qualification added to:
```
While building module 'std' imported from /home/nikolask/llvm-projects/libcxx/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp:13:
In file included from <module-includes>:17:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/math.h:309:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/limits:107:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/type_traits:432:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_reference.h:13:
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:28:43: error: declaration of 'declval' must be imported from module 'std.utility.__utility.declval' before it is required
using __cond_type = decltype(false ? std::declval<_Tp>() : std::declval<_Up>());
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__utility/declval.h:30:34: note: declaration here is not visible
decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT;
^
/home/nikolask/llvm-projects/libcxx/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp:13:10: fatal error: could not build module 'std'
#include <functional>
~~~~~~~~^
2 errors generated.
```
Reviewed By: ldionne, Mordante, #libc
Spies: libcxx-commits
Differential Revision: https://reviews.llvm.org/D130854
Added:
libcxx/test/tools/clang_tidy_checks/qualify_declval.cpp
libcxx/test/tools/clang_tidy_checks/qualify_declval.hpp
Modified:
libcxx/include/__algorithm/comp_ref_type.h
libcxx/include/__algorithm/iter_swap.h
libcxx/include/__compare/compare_three_way_result.h
libcxx/include/__compare/synth_three_way.h
libcxx/include/__concepts/common_with.h
libcxx/include/__concepts/convertible_to.h
libcxx/include/__format/format_arg.h
libcxx/include/__functional/invoke.h
libcxx/include/__functional/reference_wrapper.h
libcxx/include/__functional/weak_result_type.h
libcxx/include/__iterator/advance.h
libcxx/include/__iterator/common_iterator.h
libcxx/include/__iterator/incrementable_traits.h
libcxx/include/__iterator/iter_move.h
libcxx/include/__iterator/iter_swap.h
libcxx/include/__iterator/iterator_traits.h
libcxx/include/__iterator/move_iterator.h
libcxx/include/__iterator/reverse_iterator.h
libcxx/include/__memory/allocator_traits.h
libcxx/include/__memory/construct_at.h
libcxx/include/__memory/pointer_traits.h
libcxx/include/__memory/ranges_construct_at.h
libcxx/include/__memory/shared_ptr.h
libcxx/include/__random/is_valid.h
libcxx/include/__ranges/access.h
libcxx/include/__ranges/all.h
libcxx/include/__ranges/concepts.h
libcxx/include/__ranges/ref_view.h
libcxx/include/__ranges/size.h
libcxx/include/__ranges/zip_view.h
libcxx/include/__type_traits/common_reference.h
libcxx/include/__type_traits/common_type.h
libcxx/include/__type_traits/is_allocator.h
libcxx/include/__type_traits/is_convertible.h
libcxx/include/__type_traits/is_destructible.h
libcxx/include/__type_traits/is_nothrow_constructible.h
libcxx/include/__type_traits/is_nothrow_convertible.h
libcxx/include/__type_traits/is_nothrow_destructible.h
libcxx/include/__type_traits/is_swappable.h
libcxx/include/__type_traits/promote.h
libcxx/include/experimental/propagate_const
libcxx/include/istream
libcxx/include/optional
libcxx/include/ostream
libcxx/include/scoped_allocator
libcxx/include/variant
libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
libcxx/test/tools/clang_tidy_checks/libcpp_module.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/comp_ref_type.h b/libcxx/include/__algorithm/comp_ref_type.h
index f0a0a31665025..f2338e144688b 100644
--- a/libcxx/include/__algorithm/comp_ref_type.h
+++ b/libcxx/include/__algorithm/comp_ref_type.h
@@ -49,8 +49,8 @@ struct __debug_less
template <class _LHS, class _RHS>
_LIBCPP_CONSTEXPR_SINCE_CXX14
inline _LIBCPP_INLINE_VISIBILITY
- decltype((void)declval<_Compare&>()(
- declval<_LHS &>(), declval<_RHS &>()))
+ decltype((void)std::declval<_Compare&>()(
+ std::declval<_LHS &>(), std::declval<_RHS &>()))
__do_compare_assert(int, _LHS & __l, _RHS & __r) {
_LIBCPP_DEBUG_ASSERT(!__comp_(__l, __r),
"Comparator does not induce a strict weak ordering");
diff --git a/libcxx/include/__algorithm/iter_swap.h b/libcxx/include/__algorithm/iter_swap.h
index 0d93f7f756bc8..44422b5de0f07 100644
--- a/libcxx/include/__algorithm/iter_swap.h
+++ b/libcxx/include/__algorithm/iter_swap.h
@@ -23,7 +23,7 @@ template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 void iter_swap(_ForwardIterator1 __a,
_ForwardIterator2 __b)
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
- _NOEXCEPT_(_NOEXCEPT_(swap(*declval<_ForwardIterator1>(), *declval<_ForwardIterator2>()))) {
+ _NOEXCEPT_(_NOEXCEPT_(swap(*std::declval<_ForwardIterator1>(), *std::declval<_ForwardIterator2>()))) {
swap(*__a, *__b);
}
diff --git a/libcxx/include/__compare/compare_three_way_result.h b/libcxx/include/__compare/compare_three_way_result.h
index e668cdb24d935..8885d7effad15 100644
--- a/libcxx/include/__compare/compare_three_way_result.h
+++ b/libcxx/include/__compare/compare_three_way_result.h
@@ -26,9 +26,9 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result { };
template<class _Tp, class _Up>
struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<_Tp, _Up, decltype(
- declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>(), void()
+ std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void()
)> {
- using type = decltype(declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>());
+ using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
};
template<class _Tp, class _Up = _Tp>
diff --git a/libcxx/include/__compare/synth_three_way.h b/libcxx/include/__compare/synth_three_way.h
index fa8cbda79ba27..7d338987e0d42 100644
--- a/libcxx/include/__compare/synth_three_way.h
+++ b/libcxx/include/__compare/synth_three_way.h
@@ -42,7 +42,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
};
template <class _Tp, class _Up = _Tp>
-using __synth_three_way_result = decltype(std::__synth_three_way(declval<_Tp&>(), declval<_Up&>()));
+using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>()));
#endif // _LIBCPP_STD_VER > 17
diff --git a/libcxx/include/__concepts/common_with.h b/libcxx/include/__concepts/common_with.h
index 9bd8bf1eb59fb..569a0ee3b7690 100644
--- a/libcxx/include/__concepts/common_with.h
+++ b/libcxx/include/__concepts/common_with.h
@@ -31,8 +31,8 @@ template<class _Tp, class _Up>
concept common_with =
same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>> &&
requires {
- static_cast<common_type_t<_Tp, _Up>>(declval<_Tp>());
- static_cast<common_type_t<_Tp, _Up>>(declval<_Up>());
+ static_cast<common_type_t<_Tp, _Up>>(std::declval<_Tp>());
+ static_cast<common_type_t<_Tp, _Up>>(std::declval<_Up>());
} &&
common_reference_with<
add_lvalue_reference_t<const _Tp>,
diff --git a/libcxx/include/__concepts/convertible_to.h b/libcxx/include/__concepts/convertible_to.h
index a1c2c3a1fb83b..2c1d2674100fc 100644
--- a/libcxx/include/__concepts/convertible_to.h
+++ b/libcxx/include/__concepts/convertible_to.h
@@ -27,7 +27,7 @@ template<class _From, class _To>
concept convertible_to =
is_convertible_v<_From, _To> &&
requires {
- static_cast<_To>(declval<_From>());
+ static_cast<_To>(std::declval<_From>());
};
#endif // _LIBCPP_STD_VER > 17
diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 33d931ad797fe..771a03ff2fa98 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -161,7 +161,7 @@ class __basic_format_arg_value {
using _Dp = remove_cvref_t<_Tp>;
using _Formatter = typename _Context::template formatter_type<_Dp>;
constexpr bool __const_formattable =
- requires { _Formatter().format(declval<const _Dp&>(), declval<_Context&>()); };
+ requires { _Formatter().format(std::declval<const _Dp&>(), std::declval<_Context&>()); };
using _Qp = conditional_t<__const_formattable, const _Dp, _Dp>;
static_assert(__const_formattable || !is_const_v<remove_reference_t<_Tp>>, "Mandated by [format.arg]/18");
diff --git a/libcxx/include/__functional/invoke.h b/libcxx/include/__functional/invoke.h
index a2ac5f217f709..48e6eac3ce98f 100644
--- a/libcxx/include/__functional/invoke.h
+++ b/libcxx/include/__functional/invoke.h
@@ -398,7 +398,7 @@ template <class _Ret, class _Fp, class ..._Args>
struct __invokable_r
{
template <class _XFp, class ..._XArgs>
- static decltype(std::__invoke(declval<_XFp>(), declval<_XArgs>()...)) __try_call(int);
+ static decltype(std::__invoke(std::declval<_XFp>(), std::declval<_XArgs>()...)) __try_call(int);
template <class _XFp, class ..._XArgs>
static __nat __try_call(...);
@@ -432,7 +432,7 @@ struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
static const bool value = false;
#else
static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
- _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...)));
+ _VSTD::__invoke(std::declval<_Fp>(), std::declval<_Args>()...)));
#endif
};
@@ -443,7 +443,7 @@ struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
static const bool value = false;
#else
static const bool value = noexcept(
- _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...));
+ _VSTD::__invoke(std::declval<_Fp>(), std::declval<_Args>()...));
#endif
};
diff --git a/libcxx/include/__functional/reference_wrapper.h b/libcxx/include/__functional/reference_wrapper.h
index 481fe293b0cd3..c377b64377018 100644
--- a/libcxx/include/__functional/reference_wrapper.h
+++ b/libcxx/include/__functional/reference_wrapper.h
@@ -38,9 +38,9 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp>
static void __fun(_Tp&&) = delete;
public:
- template <class _Up, class = __enable_if_t<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(declval<_Up>())) > >
+ template <class _Up, class = __enable_if_t<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(std::declval<_Up>())) > >
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
- reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(declval<_Up>()))) {
+ reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(std::declval<_Up>()))) {
type& __f = static_cast<_Up&&>(__u);
__f_ = _VSTD::addressof(__f);
}
diff --git a/libcxx/include/__functional/weak_result_type.h b/libcxx/include/__functional/weak_result_type.h
index 6bfcbbfdd62b0..18d1bf718c4e6 100644
--- a/libcxx/include/__functional/weak_result_type.h
+++ b/libcxx/include/__functional/weak_result_type.h
@@ -286,7 +286,7 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
template <class _Tp, class ..._Args>
struct __invoke_return
{
- typedef decltype(_VSTD::__invoke(declval<_Tp>(), declval<_Args>()...)) type;
+ typedef decltype(_VSTD::__invoke(std::declval<_Tp>(), std::declval<_Args>()...)) type;
};
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h
index 2f6a72e83f48a..154c2736f313b 100644
--- a/libcxx/include/__iterator/advance.h
+++ b/libcxx/include/__iterator/advance.h
@@ -58,7 +58,7 @@ void __advance(_RandIter& __i, typename iterator_traits<_RandIter>::
diff erence_t
template <
class _InputIter, class _Distance,
- class _IntegralDistance = decltype(_VSTD::__convert_to_integral(declval<_Distance>())),
+ class _IntegralDistance = decltype(_VSTD::__convert_to_integral(std::declval<_Distance>())),
class = __enable_if_t<is_integral<_IntegralDistance>::value> >
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
void advance(_InputIter& __i, _Distance __orig_n) {
diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h
index e45f602373044..f7883e2c372f7 100644
--- a/libcxx/include/__iterator/common_iterator.h
+++ b/libcxx/include/__iterator/common_iterator.h
@@ -217,7 +217,7 @@ class common_iterator {
}
_LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i)
- noexcept(noexcept(ranges::iter_move(declval<const _Iter&>())))
+ noexcept(noexcept(ranges::iter_move(std::declval<const _Iter&>())))
requires input_iterator<_Iter>
{
_LIBCPP_ASSERT(std::holds_alternative<_Iter>(__i.__hold_), "Attempted to iter_move a non-dereferenceable common_iterator");
@@ -226,7 +226,7 @@ class common_iterator {
template<indirectly_swappable<_Iter> _I2, class _S2>
_LIBCPP_HIDE_FROM_ABI friend constexpr void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y)
- noexcept(noexcept(ranges::iter_swap(declval<const _Iter&>(), declval<const _I2&>())))
+ noexcept(noexcept(ranges::iter_swap(std::declval<const _Iter&>(), std::declval<const _I2&>())))
{
_LIBCPP_ASSERT(std::holds_alternative<_Iter>(__x.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator");
_LIBCPP_ASSERT(std::holds_alternative<_I2>(__y.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator");
@@ -257,7 +257,7 @@ struct __arrow_type_or_void {
template<class _Iter, class _Sent>
requires __common_iter_has_ptr_op<_Iter, _Sent>
struct __arrow_type_or_void<_Iter, _Sent> {
- using type = decltype(declval<const common_iterator<_Iter, _Sent>&>().operator->());
+ using type = decltype(std::declval<const common_iterator<_Iter, _Sent>&>().operator->());
};
template<input_iterator _Iter, class _Sent>
diff --git a/libcxx/include/__iterator/incrementable_traits.h b/libcxx/include/__iterator/incrementable_traits.h
index eb1b2469378b4..3d06dc05359b1 100644
--- a/libcxx/include/__iterator/incrementable_traits.h
+++ b/libcxx/include/__iterator/incrementable_traits.h
@@ -57,7 +57,7 @@ concept __has_integral_minus =
template<__has_integral_minus _Tp>
requires (!__has_member_
diff erence_type<_Tp>)
struct incrementable_traits<_Tp> {
- using
diff erence_type = make_signed_t<decltype(declval<_Tp>() - declval<_Tp>())>;
+ using
diff erence_type = make_signed_t<decltype(std::declval<_Tp>() - std::declval<_Tp>())>;
};
template <class>
diff --git a/libcxx/include/__iterator/iter_move.h b/libcxx/include/__iterator/iter_move.h
index d8ab48af754df..a7d9413fb84b2 100644
--- a/libcxx/include/__iterator/iter_move.h
+++ b/libcxx/include/__iterator/iter_move.h
@@ -95,7 +95,7 @@ inline namespace __cpo {
template<__dereferenceable _Tp>
requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __can_reference; }
-using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp&>()));
+using iter_rvalue_reference_t = decltype(ranges::iter_move(std::declval<_Tp&>()));
#endif // _LIBCPP_STD_VER > 17
diff --git a/libcxx/include/__iterator/iter_swap.h b/libcxx/include/__iterator/iter_swap.h
index 5cc4272e16041..d4c0dca1f63d9 100644
--- a/libcxx/include/__iterator/iter_swap.h
+++ b/libcxx/include/__iterator/iter_swap.h
@@ -82,7 +82,7 @@ namespace __iter_swap {
constexpr void operator()(_T1&& __x, _T2&& __y) const
noexcept(noexcept(iter_value_t<_T2>(ranges::iter_move(__y))) &&
noexcept(*__y = ranges::iter_move(__x)) &&
- noexcept(*_VSTD::forward<_T1>(__x) = declval<iter_value_t<_T2>>()))
+ noexcept(*_VSTD::forward<_T1>(__x) = std::declval<iter_value_t<_T2>>()))
{
iter_value_t<_T2> __old(ranges::iter_move(__y));
*__y = ranges::iter_move(__x);
diff --git a/libcxx/include/__iterator/iterator_traits.h b/libcxx/include/__iterator/iterator_traits.h
index ebb7fdc5bd287..c9d8944bfee32 100644
--- a/libcxx/include/__iterator/iterator_traits.h
+++ b/libcxx/include/__iterator/iterator_traits.h
@@ -60,7 +60,7 @@ concept __dereferenceable = requires(_Tp& __t) {
// [iterator.traits]
template<__dereferenceable _Tp>
-using iter_reference_t = decltype(*declval<_Tp&>());
+using iter_reference_t = decltype(*std::declval<_Tp&>());
#endif // _LIBCPP_STD_VER > 17
@@ -273,7 +273,7 @@ struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typ
template<class _Ip>
requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>)
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
- using type = decltype(declval<_Ip&>().operator->());
+ using type = decltype(std::declval<_Ip&>().operator->());
};
// Otherwise, `reference` names `iter-reference-t<I>`.
diff --git a/libcxx/include/__iterator/move_iterator.h b/libcxx/include/__iterator/move_iterator.h
index 6475f722778d3..c0e21092a33f9 100644
--- a/libcxx/include/__iterator/move_iterator.h
+++ b/libcxx/include/__iterator/move_iterator.h
@@ -53,7 +53,7 @@ struct __move_iter_category_base<_Iter> {
template<class _Iter, class _Sent>
concept __move_iter_comparable = requires {
- { declval<const _Iter&>() == declval<_Sent>() } -> convertible_to<bool>;
+ { std::declval<const _Iter&>() == std::declval<_Sent>() } -> convertible_to<bool>;
};
#endif // _LIBCPP_STD_VER > 17
diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h
index 299b971791b73..79eb4a3c5e892 100644
--- a/libcxx/include/__iterator/reverse_iterator.h
+++ b/libcxx/include/__iterator/reverse_iterator.h
@@ -184,7 +184,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
_LIBCPP_HIDE_FROM_ABI friend constexpr
iter_rvalue_reference_t<_Iter> iter_move(const reverse_iterator& __i)
noexcept(is_nothrow_copy_constructible_v<_Iter> &&
- noexcept(ranges::iter_move(--declval<_Iter&>()))) {
+ noexcept(ranges::iter_move(--std::declval<_Iter&>()))) {
auto __tmp = __i.base();
return ranges::iter_move(--__tmp);
}
@@ -194,7 +194,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
void iter_swap(const reverse_iterator& __x, const reverse_iterator<_Iter2>& __y)
noexcept(is_nothrow_copy_constructible_v<_Iter> &&
is_nothrow_copy_constructible_v<_Iter2> &&
- noexcept(ranges::iter_swap(--declval<_Iter&>(), --declval<_Iter2&>()))) {
+ noexcept(ranges::iter_swap(--std::declval<_Iter&>(), --std::declval<_Iter2&>()))) {
auto __xtmp = __x.base();
auto __ytmp = __y.base();
ranges::iter_swap(--__xtmp, --__ytmp);
@@ -401,7 +401,7 @@ class __unconstrained_reverse_iterator {
_LIBCPP_HIDE_FROM_ABI friend constexpr
iter_rvalue_reference_t<_Iter> iter_move(const __unconstrained_reverse_iterator& __i)
noexcept(is_nothrow_copy_constructible_v<_Iter> &&
- noexcept(ranges::iter_move(--declval<_Iter&>()))) {
+ noexcept(ranges::iter_move(--std::declval<_Iter&>()))) {
auto __tmp = __i.base();
return ranges::iter_move(--__tmp);
}
diff --git a/libcxx/include/__memory/allocator_traits.h b/libcxx/include/__memory/allocator_traits.h
index 348d16cc5f4f0..3a23b47c74b34 100644
--- a/libcxx/include/__memory/allocator_traits.h
+++ b/libcxx/include/__memory/allocator_traits.h
@@ -187,7 +187,7 @@ struct __has_allocate_hint : false_type { };
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
struct __has_allocate_hint<_Alloc, _SizeType, _ConstVoidPtr, decltype(
- (void)declval<_Alloc>().allocate(declval<_SizeType>(), declval<_ConstVoidPtr>())
+ (void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>())
)> : true_type { };
// __has_construct
@@ -196,7 +196,7 @@ struct __has_construct_impl : false_type { };
template <class _Alloc, class ..._Args>
struct __has_construct_impl<decltype(
- (void)declval<_Alloc>().construct(declval<_Args>()...)
+ (void)std::declval<_Alloc>().construct(std::declval<_Args>()...)
), _Alloc, _Args...> : true_type { };
template <class _Alloc, class ..._Args>
@@ -208,7 +208,7 @@ struct __has_destroy : false_type { };
template <class _Alloc, class _Pointer>
struct __has_destroy<_Alloc, _Pointer, decltype(
- (void)declval<_Alloc>().destroy(declval<_Pointer>())
+ (void)std::declval<_Alloc>().destroy(std::declval<_Pointer>())
)> : true_type { };
// __has_max_size
@@ -217,7 +217,7 @@ struct __has_max_size : false_type { };
template <class _Alloc>
struct __has_max_size<_Alloc, decltype(
- (void)declval<_Alloc&>().max_size()
+ (void)std::declval<_Alloc&>().max_size()
)> : true_type { };
// __has_select_on_container_copy_construction
@@ -226,7 +226,7 @@ struct __has_select_on_container_copy_construction : false_type { };
template <class _Alloc>
struct __has_select_on_container_copy_construction<_Alloc, decltype(
- (void)declval<_Alloc>().select_on_container_copy_construction()
+ (void)std::declval<_Alloc>().select_on_container_copy_construction()
)> : true_type { };
_LIBCPP_SUPPRESS_DEPRECATED_POP
diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index 7f13b26ac41c8..ffee0022c2433 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -32,7 +32,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
-template <class _Tp, class... _Args, class = decltype(::new(declval<void*>()) _Tp(declval<_Args>()...))>
+template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
_LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) {
_LIBCPP_ASSERT(__location != nullptr, "null pointer given to construct_at");
return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...);
@@ -40,7 +40,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __
#endif
-template <class _Tp, class... _Args, class = decltype(::new(declval<void*>()) _Tp(declval<_Args>()...))>
+template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
#if _LIBCPP_STD_VER > 17
return std::construct_at(__location, std::forward<_Args>(__args)...);
diff --git a/libcxx/include/__memory/pointer_traits.h b/libcxx/include/__memory/pointer_traits.h
index 67f83f82a01ee..c4f20def45401 100644
--- a/libcxx/include/__memory/pointer_traits.h
+++ b/libcxx/include/__memory/pointer_traits.h
@@ -179,7 +179,7 @@ struct _HasToAddress : false_type {};
template <class _Pointer>
struct _HasToAddress<_Pointer,
- decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))
+ decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()))
> : true_type {};
template <class _Pointer, class = void>
@@ -187,7 +187,7 @@ struct _HasArrow : false_type {};
template <class _Pointer>
struct _HasArrow<_Pointer,
- decltype((void)declval<const _Pointer&>().operator->())
+ decltype((void)std::declval<const _Pointer&>().operator->())
> : true_type {};
template <class _Pointer>
@@ -200,7 +200,7 @@ template <class _Pointer, class = __enable_if_t<
_And<is_class<_Pointer>, _IsFancyPointer<_Pointer> >::value
> >
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename decay<decltype(__to_address_helper<_Pointer>::__call(declval<const _Pointer&>()))>::type
+typename decay<decltype(__to_address_helper<_Pointer>::__call(std::declval<const _Pointer&>()))>::type
__to_address(const _Pointer& __p) _NOEXCEPT {
return __to_address_helper<_Pointer>::__call(__p);
}
@@ -208,16 +208,16 @@ __to_address(const _Pointer& __p) _NOEXCEPT {
template <class _Pointer, class>
struct __to_address_helper {
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- static decltype(_VSTD::__to_address(declval<const _Pointer&>().operator->()))
+ static decltype(_VSTD::__to_address(std::declval<const _Pointer&>().operator->()))
__call(const _Pointer& __p) _NOEXCEPT {
return _VSTD::__to_address(__p.operator->());
}
};
template <class _Pointer>
-struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))> {
+struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()))> {
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- static decltype(pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))
+ static decltype(pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()))
__call(const _Pointer& __p) _NOEXCEPT {
return pointer_traits<_Pointer>::to_address(__p);
}
diff --git a/libcxx/include/__memory/ranges_construct_at.h b/libcxx/include/__memory/ranges_construct_at.h
index 19cd0ff7e8949..e63585d1ab633 100644
--- a/libcxx/include/__memory/ranges_construct_at.h
+++ b/libcxx/include/__memory/ranges_construct_at.h
@@ -39,7 +39,7 @@ namespace __construct_at {
struct __fn {
template<class _Tp, class... _Args, class = decltype(
- ::new (declval<void*>()) _Tp(declval<_Args>()...)
+ ::new (std::declval<void*>()) _Tp(std::declval<_Args>()...)
)>
_LIBCPP_HIDE_FROM_ABI
constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const {
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index e598ad2b8a308..a76e262ea0516 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -366,15 +366,15 @@ struct __compatible_with
template <class _Ptr, class = void>
struct __is_deletable : false_type { };
template <class _Ptr>
-struct __is_deletable<_Ptr, decltype(delete declval<_Ptr>())> : true_type { };
+struct __is_deletable<_Ptr, decltype(delete std::declval<_Ptr>())> : true_type { };
template <class _Ptr, class = void>
struct __is_array_deletable : false_type { };
template <class _Ptr>
-struct __is_array_deletable<_Ptr, decltype(delete[] declval<_Ptr>())> : true_type { };
+struct __is_array_deletable<_Ptr, decltype(delete[] std::declval<_Ptr>())> : true_type { };
template <class _Dp, class _Pt,
- class = decltype(declval<_Dp>()(declval<_Pt>()))>
+ class = decltype(std::declval<_Dp>()(std::declval<_Pt>()))>
static true_type __well_formed_deleter_test(int);
template <class, class>
diff --git a/libcxx/include/__random/is_valid.h b/libcxx/include/__random/is_valid.h
index be3b61b8dc019..1d65de00fbb6f 100644
--- a/libcxx/include/__random/is_valid.h
+++ b/libcxx/include/__random/is_valid.h
@@ -53,7 +53,7 @@ template<> struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {};
template<class, class = void> struct __libcpp_random_is_valid_urng : false_type {};
template<class _Gp> struct __libcpp_random_is_valid_urng<_Gp, __enable_if_t<
is_unsigned<typename _Gp::result_type>::value &&
- _IsSame<decltype(declval<_Gp&>()()), typename _Gp::result_type>::value
+ _IsSame<decltype(std::declval<_Gp&>()()), typename _Gp::result_type>::value
> > : true_type {};
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__ranges/access.h b/libcxx/include/__ranges/access.h
index 29babf38a611f..e48a71adf7e86 100644
--- a/libcxx/include/__ranges/access.h
+++ b/libcxx/include/__ranges/access.h
@@ -105,7 +105,7 @@ inline namespace __cpo {
namespace ranges {
template <class _Tp>
- using iterator_t = decltype(ranges::begin(declval<_Tp&>()));
+ using iterator_t = decltype(ranges::begin(std::declval<_Tp&>()));
} // namespace ranges
// [range.access.end]
diff --git a/libcxx/include/__ranges/all.h b/libcxx/include/__ranges/all.h
index c30c9e32e4c70..511f7b3b46f3a 100644
--- a/libcxx/include/__ranges/all.h
+++ b/libcxx/include/__ranges/all.h
@@ -73,7 +73,7 @@ inline namespace __cpo {
} // namespace __cpo
template<ranges::viewable_range _Range>
-using all_t = decltype(views::all(declval<_Range>()));
+using all_t = decltype(views::all(std::declval<_Range>()));
} // namespace ranges::views
diff --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h
index 730b83cde2df1..e34c545578ab1 100644
--- a/libcxx/include/__ranges/concepts.h
+++ b/libcxx/include/__ranges/concepts.h
@@ -59,7 +59,7 @@ namespace ranges {
// `iterator_t` defined in <__ranges/access.h>
template <range _Rp>
- using sentinel_t = decltype(ranges::end(declval<_Rp&>()));
+ using sentinel_t = decltype(ranges::end(std::declval<_Rp&>()));
template <range _Rp>
using range_
diff erence_t = iter_
diff erence_t<iterator_t<_Rp>>;
@@ -78,7 +78,7 @@ namespace ranges {
concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
template<sized_range _Rp>
- using range_size_t = decltype(ranges::size(declval<_Rp&>()));
+ using range_size_t = decltype(ranges::size(std::declval<_Rp&>()));
// `disable_sized_range` defined in `<__ranges/size.h>`
diff --git a/libcxx/include/__ranges/ref_view.h b/libcxx/include/__ranges/ref_view.h
index e949f75344139..1e5f7466f3216 100644
--- a/libcxx/include/__ranges/ref_view.h
+++ b/libcxx/include/__ranges/ref_view.h
@@ -47,7 +47,7 @@ namespace ranges {
public:
template<class _Tp>
requires __
diff erent_from<_Tp, ref_view> &&
- convertible_to<_Tp, _Range&> && requires { __fun(declval<_Tp>()); }
+ convertible_to<_Tp, _Range&> && requires { __fun(std::declval<_Tp>()); }
_LIBCPP_HIDE_FROM_ABI
constexpr ref_view(_Tp&& __t)
: __range_(std::addressof(static_cast<_Range&>(std::forward<_Tp>(__t))))
diff --git a/libcxx/include/__ranges/size.h b/libcxx/include/__ranges/size.h
index 4068a21bb585c..0ac8d63063d49 100644
--- a/libcxx/include/__ranges/size.h
+++ b/libcxx/include/__ranges/size.h
@@ -21,6 +21,7 @@
#include <__type_traits/make_unsigned.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/auto_cast.h>
+#include <__utility/declval.h>
#include <cstddef>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -70,7 +71,7 @@ concept __
diff erence =
__class_or_enum<remove_cvref_t<_Tp>> &&
requires(_Tp&& __t) {
{ ranges::begin(__t) } -> forward_iterator;
- { ranges::end(__t) } -> sized_sentinel_for<decltype(ranges::begin(declval<_Tp>()))>;
+ { ranges::end(__t) } -> sized_sentinel_for<decltype(ranges::begin(std::declval<_Tp>()))>;
};
struct __fn {
diff --git a/libcxx/include/__ranges/zip_view.h b/libcxx/include/__ranges/zip_view.h
index 6eb0ffdf84e37..5624726e13ee6 100644
--- a/libcxx/include/__ranges/zip_view.h
+++ b/libcxx/include/__ranges/zip_view.h
@@ -403,15 +403,15 @@ class zip_view<_Views...>::__iterator : public __zip_view_iterator_category_base
_LIBCPP_HIDE_FROM_ABI
friend constexpr auto iter_move(const __iterator& __i) noexcept(
- (noexcept(ranges::iter_move(declval<const iterator_t<__maybe_const<_Const, _Views>>&>())) && ...) &&
+ (noexcept(ranges::iter_move(std::declval<const iterator_t<__maybe_const<_Const, _Views>>&>())) && ...) &&
(is_nothrow_move_constructible_v<range_rvalue_reference_t<__maybe_const<_Const, _Views>>> && ...)) {
return ranges::__tuple_transform(ranges::iter_move, __i.__current_);
}
_LIBCPP_HIDE_FROM_ABI
friend constexpr void iter_swap(const __iterator& __l, const __iterator& __r) noexcept(
- (noexcept(ranges::iter_swap(declval<const iterator_t<__maybe_const<_Const, _Views>>&>(),
- declval<const iterator_t<__maybe_const<_Const, _Views>>&>())) &&
+ (noexcept(ranges::iter_swap(std::declval<const iterator_t<__maybe_const<_Const, _Views>>&>(),
+ std::declval<const iterator_t<__maybe_const<_Const, _Views>>&>())) &&
...))
requires(indirectly_swappable<iterator_t<__maybe_const<_Const, _Views>>> && ...) {
ranges::__tuple_zip_for_each(ranges::iter_swap, __l.__current_, __r.__current_);
diff --git a/libcxx/include/__type_traits/common_reference.h b/libcxx/include/__type_traits/common_reference.h
index 559d39858ec88..f9195865c89e2 100644
--- a/libcxx/include/__type_traits/common_reference.h
+++ b/libcxx/include/__type_traits/common_reference.h
@@ -31,7 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// Let COND_RES(X, Y) be:
template <class _Xp, class _Yp>
using __cond_res =
- decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
+ decltype(false ? std::declval<_Xp(&)()>()() : std::declval<_Yp(&)()>()());
// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
diff --git a/libcxx/include/__type_traits/common_type.h b/libcxx/include/__type_traits/common_type.h
index 8009142dfea4f..6d2df6c9b3e41 100644
--- a/libcxx/include/__type_traits/common_type.h
+++ b/libcxx/include/__type_traits/common_type.h
@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
// Let COND_RES(X, Y) be:
template <class _Tp, class _Up>
-using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
+using __cond_type = decltype(false ? std::declval<_Tp>() : std::declval<_Up>());
template <class _Tp, class _Up, class = void>
struct __common_type3 {};
@@ -47,10 +47,10 @@ struct __common_type2_imp {};
// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
template <class _Tp, class _Up>
-struct __common_type2_imp<_Tp, _Up, __void_t<decltype(true ? declval<_Tp>() : declval<_Up>())> >
+struct __common_type2_imp<_Tp, _Up, __void_t<decltype(true ? std::declval<_Tp>() : std::declval<_Up>())> >
{
typedef _LIBCPP_NODEBUG typename decay<decltype(
- true ? declval<_Tp>() : declval<_Up>()
+ true ? std::declval<_Tp>() : std::declval<_Up>()
)>::type type;
};
diff --git a/libcxx/include/__type_traits/is_allocator.h b/libcxx/include/__type_traits/is_allocator.h
index 53401e9f4f5cd..ee4154d7e4a43 100644
--- a/libcxx/include/__type_traits/is_allocator.h
+++ b/libcxx/include/__type_traits/is_allocator.h
@@ -27,7 +27,7 @@ struct __is_allocator : false_type {};
template<typename _Alloc>
struct __is_allocator<_Alloc,
__void_t<typename _Alloc::value_type>,
- __void_t<decltype(declval<_Alloc&>().allocate(size_t(0)))>
+ __void_t<decltype(std::declval<_Alloc&>().allocate(size_t(0)))>
>
: true_type {};
diff --git a/libcxx/include/__type_traits/is_convertible.h b/libcxx/include/__type_traits/is_convertible.h
index 1085d632a51b4..5f77fd4d70649 100644
--- a/libcxx/include/__type_traits/is_convertible.h
+++ b/libcxx/include/__type_traits/is_convertible.h
@@ -40,7 +40,7 @@ struct __is_convertible_test : public false_type {};
template <class _From, class _To>
struct __is_convertible_test<_From, _To,
- decltype(__is_convertible_imp::__test_convert<_To>(declval<_From>()))> : public true_type
+ decltype(__is_convertible_imp::__test_convert<_To>(std::declval<_From>()))> : public true_type
{};
template <class _Tp, bool _IsArray = is_array<_Tp>::value,
diff --git a/libcxx/include/__type_traits/is_destructible.h b/libcxx/include/__type_traits/is_destructible.h
index e0a0d3c1f19a2..376d74de86e98 100644
--- a/libcxx/include/__type_traits/is_destructible.h
+++ b/libcxx/include/__type_traits/is_destructible.h
@@ -48,7 +48,7 @@ template <typename _Tp>
struct __is_destructor_wellformed {
template <typename _Tp1>
static true_type __test (
- typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
+ typename __is_destructible_apply<decltype(std::declval<_Tp1&>().~_Tp1())>::type
);
template <typename _Tp1>
diff --git a/libcxx/include/__type_traits/is_nothrow_constructible.h b/libcxx/include/__type_traits/is_nothrow_constructible.h
index 4caad81ad11ca..8919b7933c2b2 100644
--- a/libcxx/include/__type_traits/is_nothrow_constructible.h
+++ b/libcxx/include/__type_traits/is_nothrow_constructible.h
@@ -34,7 +34,7 @@ template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_cons
template <class _Tp, class... _Args>
struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
- : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
+ : public integral_constant<bool, noexcept(_Tp(std::declval<_Args>()...))>
{
};
@@ -43,7 +43,7 @@ void __implicit_conversion_to(_Tp) noexcept { }
template <class _Tp, class _Arg>
struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
- : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
+ : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(std::declval<_Arg>()))>
{
};
diff --git a/libcxx/include/__type_traits/is_nothrow_convertible.h b/libcxx/include/__type_traits/is_nothrow_convertible.h
index 712b6f2cf4b8c..a8ca1c4c413c4 100644
--- a/libcxx/include/__type_traits/is_nothrow_convertible.h
+++ b/libcxx/include/__type_traits/is_nothrow_convertible.h
@@ -30,7 +30,7 @@ template <typename _Tp>
static void __test_noexcept(_Tp) noexcept;
template<typename _Fm, typename _To>
-static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(declval<_Fm>()))>
+static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(std::declval<_Fm>()))>
__is_nothrow_convertible_test();
template <typename _Fm, typename _To>
diff --git a/libcxx/include/__type_traits/is_nothrow_destructible.h b/libcxx/include/__type_traits/is_nothrow_destructible.h
index 050362f9f4286..03ebf440492d0 100644
--- a/libcxx/include/__type_traits/is_nothrow_destructible.h
+++ b/libcxx/include/__type_traits/is_nothrow_destructible.h
@@ -36,7 +36,7 @@ struct __libcpp_is_nothrow_destructible<false, _Tp>
template <class _Tp>
struct __libcpp_is_nothrow_destructible<true, _Tp>
- : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
+ : public integral_constant<bool, noexcept(std::declval<_Tp>().~_Tp()) >
{
};
diff --git a/libcxx/include/__type_traits/is_swappable.h b/libcxx/include/__type_traits/is_swappable.h
index a13118228272a..3821de17f66e2 100644
--- a/libcxx/include/__type_traits/is_swappable.h
+++ b/libcxx/include/__type_traits/is_swappable.h
@@ -64,7 +64,7 @@ template <class _Tp, class _Up = _Tp,
struct __swappable_with
{
template <class _LHS, class _RHS>
- static decltype(swap(declval<_LHS>(), declval<_RHS>()))
+ static decltype(swap(std::declval<_LHS>(), std::declval<_RHS>()))
__test_swap(int);
template <class, class>
static __nat __test_swap(long);
@@ -84,8 +84,8 @@ template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _U
struct __nothrow_swappable_with {
static const bool value =
#ifndef _LIBCPP_HAS_NO_NOEXCEPT
- noexcept(swap(declval<_Tp>(), declval<_Up>()))
- && noexcept(swap(declval<_Up>(), declval<_Tp>()));
+ noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
+ && noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()));
#else
false;
#endif
diff --git a/libcxx/include/__type_traits/promote.h b/libcxx/include/__type_traits/promote.h
index e647dff4690cd..c2af327c64f7b 100644
--- a/libcxx/include/__type_traits/promote.h
+++ b/libcxx/include/__type_traits/promote.h
@@ -40,7 +40,7 @@ struct __numeric_type
static double __test(double);
static long double __test(long double);
- typedef decltype(__test(declval<_Tp>())) type;
+ typedef decltype(__test(std::declval<_Tp>())) type;
static const bool value = _IsNotSame<type, void>::value;
};
diff --git a/libcxx/include/experimental/propagate_const b/libcxx/include/experimental/propagate_const
index 3f46205975c2f..34e917da5154b 100644
--- a/libcxx/include/experimental/propagate_const
+++ b/libcxx/include/experimental/propagate_const
@@ -139,7 +139,7 @@ template <class _Tp>
class propagate_const
{
public:
- typedef remove_reference_t<decltype(*declval<_Tp&>())> element_type;
+ typedef remove_reference_t<decltype(*std::declval<_Tp&>())> element_type;
static_assert(!is_array<_Tp>::value,
"Instantiation of propagate_const with an array type is ill-formed.");
diff --git a/libcxx/include/istream b/libcxx/include/istream
index efbcba9f2f26a..6e67d61de2af8 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -1375,7 +1375,7 @@ struct __is_istreamable : false_type { };
template <class _Stream, class _Tp>
struct __is_istreamable<_Stream, _Tp, decltype(
- declval<_Stream>() >> declval<_Tp>(), void()
+ std::declval<_Stream>() >> std::declval<_Tp>(), void()
)> : true_type { };
template <class _Stream, class _Tp, class = typename enable_if<
diff --git a/libcxx/include/optional b/libcxx/include/optional
index 6272f839c751f..6a7e2d2941dec 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -1185,8 +1185,8 @@ template<class _Tp>
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() ==
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() ==
+ std::declval<const _Up&>()), bool>,
bool
>
operator==(const optional<_Tp>& __x, const optional<_Up>& __y)
@@ -1201,8 +1201,8 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() !=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() !=
+ std::declval<const _Up&>()), bool>,
bool
>
operator!=(const optional<_Tp>& __x, const optional<_Up>& __y)
@@ -1217,8 +1217,8 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() <
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() <
+ std::declval<const _Up&>()), bool>,
bool
>
operator<(const optional<_Tp>& __x, const optional<_Up>& __y)
@@ -1233,8 +1233,8 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() >
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() >
+ std::declval<const _Up&>()), bool>,
bool
>
operator>(const optional<_Tp>& __x, const optional<_Up>& __y)
@@ -1249,8 +1249,8 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() <=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() <=
+ std::declval<const _Up&>()), bool>,
bool
>
operator<=(const optional<_Tp>& __x, const optional<_Up>& __y)
@@ -1265,8 +1265,8 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() >=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() >=
+ std::declval<const _Up&>()), bool>,
bool
>
operator>=(const optional<_Tp>& __x, const optional<_Up>& __y)
@@ -1379,8 +1379,8 @@ operator>=(nullopt_t, const optional<_Tp>& __x) noexcept
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() ==
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() ==
+ std::declval<const _Up&>()), bool>,
bool
>
operator==(const optional<_Tp>& __x, const _Up& __v)
@@ -1391,8 +1391,8 @@ operator==(const optional<_Tp>& __x, const _Up& __v)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() ==
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() ==
+ std::declval<const _Up&>()), bool>,
bool
>
operator==(const _Tp& __v, const optional<_Up>& __x)
@@ -1403,8 +1403,8 @@ operator==(const _Tp& __v, const optional<_Up>& __x)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() !=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() !=
+ std::declval<const _Up&>()), bool>,
bool
>
operator!=(const optional<_Tp>& __x, const _Up& __v)
@@ -1415,8 +1415,8 @@ operator!=(const optional<_Tp>& __x, const _Up& __v)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() !=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() !=
+ std::declval<const _Up&>()), bool>,
bool
>
operator!=(const _Tp& __v, const optional<_Up>& __x)
@@ -1427,8 +1427,8 @@ operator!=(const _Tp& __v, const optional<_Up>& __x)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() <
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() <
+ std::declval<const _Up&>()), bool>,
bool
>
operator<(const optional<_Tp>& __x, const _Up& __v)
@@ -1439,8 +1439,8 @@ operator<(const optional<_Tp>& __x, const _Up& __v)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() <
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() <
+ std::declval<const _Up&>()), bool>,
bool
>
operator<(const _Tp& __v, const optional<_Up>& __x)
@@ -1451,8 +1451,8 @@ operator<(const _Tp& __v, const optional<_Up>& __x)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() <=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() <=
+ std::declval<const _Up&>()), bool>,
bool
>
operator<=(const optional<_Tp>& __x, const _Up& __v)
@@ -1463,8 +1463,8 @@ operator<=(const optional<_Tp>& __x, const _Up& __v)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() <=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() <=
+ std::declval<const _Up&>()), bool>,
bool
>
operator<=(const _Tp& __v, const optional<_Up>& __x)
@@ -1475,8 +1475,8 @@ operator<=(const _Tp& __v, const optional<_Up>& __x)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() >
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() >
+ std::declval<const _Up&>()), bool>,
bool
>
operator>(const optional<_Tp>& __x, const _Up& __v)
@@ -1487,8 +1487,8 @@ operator>(const optional<_Tp>& __x, const _Up& __v)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() >
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() >
+ std::declval<const _Up&>()), bool>,
bool
>
operator>(const _Tp& __v, const optional<_Up>& __x)
@@ -1499,8 +1499,8 @@ operator>(const _Tp& __v, const optional<_Up>& __x)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() >=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() >=
+ std::declval<const _Up&>()), bool>,
bool
>
operator>=(const optional<_Tp>& __x, const _Up& __v)
@@ -1511,8 +1511,8 @@ operator>=(const optional<_Tp>& __x, const _Up& __v)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<
- is_convertible_v<decltype(declval<const _Tp&>() >=
- declval<const _Up&>()), bool>,
+ is_convertible_v<decltype(std::declval<const _Tp&>() >=
+ std::declval<const _Up&>()), bool>,
bool
>
operator>=(const _Tp& __v, const optional<_Up>& __x)
diff --git a/libcxx/include/ostream b/libcxx/include/ostream
index acde3709c510f..4780c763ea038 100644
--- a/libcxx/include/ostream
+++ b/libcxx/include/ostream
@@ -1063,7 +1063,7 @@ struct __is_ostreamable : false_type { };
template <class _Stream, class _Tp>
struct __is_ostreamable<_Stream, _Tp, decltype(
- declval<_Stream>() << declval<_Tp>(), void()
+ std::declval<_Stream>() << std::declval<_Tp>(), void()
)> : true_type { };
template <class _Stream, class _Tp, class = typename enable_if<
@@ -1113,7 +1113,7 @@ template<class _CharT, class _Traits, class _Yp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_same<void, __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
+ is_same<void, __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>() << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
basic_ostream<_CharT, _Traits>&
>::type
operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
diff --git a/libcxx/include/scoped_allocator b/libcxx/include/scoped_allocator
index 88e56c2b09e7c..461c67e9b6566 100644
--- a/libcxx/include/scoped_allocator
+++ b/libcxx/include/scoped_allocator
@@ -363,7 +363,7 @@ protected:
// __outermost
template <class _Alloc>
-decltype(declval<_Alloc>().outer_allocator(), true_type())
+decltype(std::declval<_Alloc>().outer_allocator(), true_type())
__has_outer_allocator_test(_Alloc&& __a);
template <class _Alloc>
@@ -374,7 +374,7 @@ template <class _Alloc>
struct __has_outer_allocator
: public common_type
<
- decltype(std::__has_outer_allocator_test(declval<_Alloc&>()))
+ decltype(std::__has_outer_allocator_test(std::declval<_Alloc&>()))
>::type
{
};
@@ -392,7 +392,7 @@ struct __outermost<_Alloc, true>
{
typedef __libcpp_remove_reference_t
<
- decltype(declval<_Alloc>().outer_allocator())
+ decltype(std::declval<_Alloc>().outer_allocator())
> _OuterAlloc;
typedef typename __outermost<_OuterAlloc>::type type;
_LIBCPP_INLINE_VISIBILITY
diff --git a/libcxx/include/variant b/libcxx/include/variant
index 2379b226b157e..13c89822ca775 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -1229,7 +1229,7 @@ struct __narrowing_check {
template <class _Dest>
static auto __test_impl(_Dest (&&)[1]) -> __type_identity<_Dest>;
template <class _Dest, class _Source>
- using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({declval<_Source>()}));
+ using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({std::declval<_Source>()}));
};
template <class _Dest, class _Source>
@@ -1747,7 +1747,7 @@ constexpr void __throw_if_valueless(_Vs&&... __vs) {
template <
class _Visitor, class... _Vs,
- typename = void_t<decltype(_VSTD::__as_variant(declval<_Vs>()))...> >
+ typename = void_t<decltype(_VSTD::__as_variant(std::declval<_Vs>()))...> >
_LIBCPP_HIDE_FROM_ABI
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
@@ -1760,7 +1760,7 @@ constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
#if _LIBCPP_STD_VER > 17
template <
class _Rp, class _Visitor, class... _Vs,
- typename = void_t<decltype(_VSTD::__as_variant(declval<_Vs>()))...> >
+ typename = void_t<decltype(_VSTD::__as_variant(std::declval<_Vs>()))...> >
_LIBCPP_HIDE_FROM_ABI
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr _Rp visit(_Visitor&& __visitor, _Vs&&... __vs) {
diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 4599f5b80e598..f5539a9303eba 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -7,7 +7,9 @@ find_package(Clang 16)
set(SOURCES
robust_against_adl.cpp
- libcpp_module.cpp)
+ libcpp_module.cpp
+ qualify_declval.cpp
+ )
if(NOT Clang_FOUND)
diff --git a/libcxx/test/tools/clang_tidy_checks/libcpp_module.cpp b/libcxx/test/tools/clang_tidy_checks/libcpp_module.cpp
index 52057592a845e..60d200c5fcb0b 100644
--- a/libcxx/test/tools/clang_tidy_checks/libcpp_module.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/libcpp_module.cpp
@@ -9,12 +9,14 @@
#include "clang-tidy/ClangTidyModule.h"
#include "clang-tidy/ClangTidyModuleRegistry.h"
#include "robust_against_adl.hpp"
+#include "qualify_declval.hpp"
namespace {
class LibcxxTestModule : public clang::tidy::ClangTidyModule {
public:
void addCheckFactories(clang::tidy::ClangTidyCheckFactories& check_factories) override {
check_factories.registerCheck<libcpp::robust_against_adl_check>("libcpp-robust-against-adl");
+ check_factories.registerCheck<libcpp::qualify_declval>("libcpp-qualify-declval");
}
};
} // namespace
diff --git a/libcxx/test/tools/clang_tidy_checks/qualify_declval.cpp b/libcxx/test/tools/clang_tidy_checks/qualify_declval.cpp
new file mode 100644
index 0000000000000..f1c84ee16e92e
--- /dev/null
+++ b/libcxx/test/tools/clang_tidy_checks/qualify_declval.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "qualify_declval.hpp"
+
+namespace {
+AST_MATCHER(clang::UnresolvedLookupExpr, requiresADL) { return Node.requiresADL(); }
+AST_MATCHER(clang::UnresolvedLookupExpr, isDeclval) { return Node.getName().getAsString() == "declval"; }
+} // namespace
+
+namespace libcpp {
+qualify_declval::qualify_declval(llvm::StringRef name, clang::tidy::ClangTidyContext* context)
+ : clang::tidy::ClangTidyCheck(name, context) {}
+
+void qualify_declval::registerMatchers(clang::ast_matchers::MatchFinder* finder) {
+ using namespace clang::ast_matchers;
+ finder->addMatcher(callExpr(has(unresolvedLookupExpr(requiresADL(), isDeclval()))).bind("ADLcall"), this);
+}
+
+void qualify_declval::check(const clang::ast_matchers::MatchFinder::MatchResult& result) {
+ if (const auto* call = result.Nodes.getNodeAs<clang::CallExpr>("ADLcall"); call != nullptr) {
+ diag(call->getBeginLoc(), "declval should be qualified to get better error messages")
+ << clang::FixItHint::CreateInsertion(call->getBeginLoc(), "std::");
+ }
+}
+} // namespace libcpp
diff --git a/libcxx/test/tools/clang_tidy_checks/qualify_declval.hpp b/libcxx/test/tools/clang_tidy_checks/qualify_declval.hpp
new file mode 100644
index 0000000000000..931f9ccf76627
--- /dev/null
+++ b/libcxx/test/tools/clang_tidy_checks/qualify_declval.hpp
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang-tidy/ClangTidyCheck.h"
+
+namespace libcpp {
+class qualify_declval : public clang::tidy::ClangTidyCheck {
+public:
+ qualify_declval(llvm::StringRef, clang::tidy::ClangTidyContext*);
+ void registerMatchers(clang::ast_matchers::MatchFinder*) override;
+ void check(const clang::ast_matchers::MatchFinder::MatchResult&) override;
+};
+} // namespace libcpp
More information about the libcxx-commits
mailing list