|
1 |
| -// RUN: %check_clang_tidy -std=c++20 %s modernize-use-constraints %t -- -- -fno-delayed-template-parsing |
| 1 | +// RUN: %check_clang_tidy -std=c++20-or-later %s modernize-use-constraints %t -- -- -fno-delayed-template-parsing |
2 | 2 |
|
3 | 3 | // NOLINTBEGIN
|
4 | 4 | namespace std {
|
@@ -756,3 +756,69 @@ abs(const number<T, ExpressionTemplates> &v) {
|
756 | 756 | }
|
757 | 757 |
|
758 | 758 | }
|
| 759 | + |
| 760 | +template <typename T> |
| 761 | +struct some_type_trait { |
| 762 | + static constexpr bool value = true; |
| 763 | +}; |
| 764 | + |
| 765 | +// Fix-its are offered even for a non-standard enable_if. |
| 766 | +namespace nonstd { |
| 767 | + |
| 768 | +template <bool Condition, typename T = void> |
| 769 | +struct enable_if : std::enable_if<Condition, T> {}; |
| 770 | + |
| 771 | +template <bool Condition, typename T = void> |
| 772 | +using enable_if_t = typename enable_if<Condition, T>::type; |
| 773 | + |
| 774 | +} |
| 775 | + |
| 776 | +template <typename T> |
| 777 | +typename nonstd::enable_if<some_type_trait<T>::value, void>::type nonstd_enable_if() {} |
| 778 | +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] |
| 779 | +// CHECK-FIXES: {{^}}void nonstd_enable_if() requires some_type_trait<T>::value {}{{$}} |
| 780 | + |
| 781 | +template <typename T> |
| 782 | +nonstd::enable_if_t<some_type_trait<T>::value, void> nonstd_enable_if_t() {} |
| 783 | +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] |
| 784 | +// CHECK-FIXES: {{^}}void nonstd_enable_if_t() requires some_type_trait<T>::value {}{{$}} |
| 785 | + |
| 786 | +template <> |
| 787 | +nonstd::enable_if_t<some_type_trait<int>::value, void> nonstd_enable_if_t<int>() {} |
| 788 | +// FIXME - Support non-dependent enable_ifs. |
| 789 | + |
| 790 | +template <typename T> |
| 791 | +typename nonstd::enable_if<some_type_trait<T>::value>::type nonstd_enable_if_one_param() {} |
| 792 | +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] |
| 793 | +// CHECK-FIXES: {{^}}void nonstd_enable_if_one_param() requires some_type_trait<T>::value {}{{$}} |
| 794 | + |
| 795 | +template <typename T> |
| 796 | +nonstd::enable_if_t<some_type_trait<T>::value> nonstd_enable_if_t_one_param() {} |
| 797 | +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] |
| 798 | +// CHECK-FIXES: {{^}}void nonstd_enable_if_t_one_param() requires some_type_trait<T>::value {}{{$}} |
| 799 | + |
| 800 | +// No fix-its are offered for an enable_if with a different signature from the standard one. |
| 801 | +namespace boost { |
| 802 | + |
| 803 | +template <typename Condition, typename T = void> |
| 804 | +struct enable_if : std::enable_if<Condition::value, T> {}; |
| 805 | + |
| 806 | +template <typename Condition, typename T = void> |
| 807 | +using enable_if_t = typename enable_if<Condition, T>::type; |
| 808 | + |
| 809 | +} |
| 810 | + |
| 811 | +template <typename T> |
| 812 | +typename boost::enable_if<some_type_trait<T>, void>::type boost_enable_if() {} |
| 813 | + |
| 814 | +template <typename T> |
| 815 | +boost::enable_if_t<some_type_trait<T>, void> boost_enable_if_t() {} |
| 816 | + |
| 817 | +template <> |
| 818 | +boost::enable_if_t<some_type_trait<int>, void> boost_enable_if_t<int>() {} |
| 819 | + |
| 820 | +template <typename T> |
| 821 | +typename boost::enable_if<some_type_trait<T>>::type boost_enable_if_one_param() {} |
| 822 | + |
| 823 | +template <typename T> |
| 824 | +boost::enable_if_t<some_type_trait<T>> boost_enable_if_t_one_param() {} |
0 commit comments