1// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -check-suffixes=',MACRO'
2// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -- \
3// RUN: -config='{CheckOptions: {modernize-type-traits.IgnoreMacros: true}}'
4// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
5
6namespace std {
7 template <typename>
8 struct is_const {
9 static constexpr bool value = true;
10 };
11
12 template <typename, typename>
13 struct is_same {
14 static constexpr bool value = true;
15 };
16
17 template<bool, typename T = void>
18 struct enable_if {
19 using type = T;
20 };
21
22 template <typename...>
23 struct common_type {
24 using type = int;
25 };
26
27inline namespace __std_lib_version1 {
28 template<typename T>
29 struct add_const {
30 using type = T;
31 };
32} // namespace __std_lib_version1
33
34namespace ext {
35 template<typename T>
36 struct add_const {
37 using type = T;
38 };
39} // namespace ext
40
41} // namespace std
42
43bool NoTemplate = std::is_const<bool>::value;
44// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
45// CHECK-FIXES-CXX17: bool NoTemplate = std::is_const_v<bool>;
46
47template<typename T>
48constexpr bool InTemplate = std::is_const<T>::value;
49// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:29: warning: use c++17 style variable templates
50// CHECK-FIXES-CXX17: constexpr bool InTemplate = std::is_const_v<T>;
51
52template<typename U, typename V>
53constexpr bool Template2Params = std::is_same<U,V>::value;
54// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
55// CHECK-FIXES-CXX17: constexpr bool Template2Params = std::is_same_v<U,V>;
56
57template<bool b>
58typename std::enable_if<b>::type inTemplate();
59// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
60// CHECK-FIXES: std::enable_if_t<b>inTemplate();
61
62typename std::enable_if<true>::type noTemplate();
63// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
64// CHECK-FIXES: std::enable_if_t<true>noTemplate();
65
66std::enable_if<true>::type noTemplateOrTypename();
67// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use c++14 style type templates
68// CHECK-FIXES: std::enable_if_t<true>noTemplateOrTypename();
69
70using UsingNoTypename = std::enable_if<true>::type;
71// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
72// CHECK-FIXES: using UsingNoTypename = std::enable_if_t<true>;
73
74using VariadicTrait = std::common_type<int, long, bool>::type;
75// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use c++14 style type templates
76// CHECK-FIXES: using VariadicTrait = std::common_type_t<int, long, bool>;
77
78using UsingSpace = std::enable_if <true>::type;
79// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use c++14 style type templates
80// CHECK-FIXES: using UsingSpace = std::enable_if_t <true>;
81
82template<bool b>
83using UsingSpaceTemplate = typename std::enable_if <b>::type;
84// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use c++14 style type templates
85// CHECK-FIXES: using UsingSpaceTemplate = std::enable_if_t <b>;
86
87bool NoTemplateSpace = std::is_const <bool> ::value;
88// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:24: warning: use c++17 style variable templates
89// CHECK-FIXES-CXX17: bool NoTemplateSpace = std::is_const_v <bool> ;
90
91template<typename T>
92constexpr bool InTemplateSpace = std::is_const <T> ::value;
93// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
94// CHECK-FIXES-CXX17: constexpr bool InTemplateSpace = std::is_const_v <T> ;
95
96// For macros, no diagnostics if IgnoreMacros is set,
97// No fixes emitted even if IgnoreMacros is unset.
98
99#define VALUE_MACRO std::is_same<int, int>::value
100bool MacroValue = VALUE_MACRO;
101// CHECK-MESSAGES-CXX17MACRO: :[[@LINE-1]]:19: warning: use c++17 style variable templates
102// CHECK-FIXES-CXX17MACRO: #define VALUE_MACRO std::is_same<int, int>::value
103
104#define TYPE_MACRO typename std::enable_if<true>::type
105using MacroType = TYPE_MACRO;
106// CHECK-MESSAGES-MACRO: :[[@LINE-1]]:19: warning: use c++14 style type templates
107// CHECK-FIXES-MACRO: #define TYPE_MACRO typename std::enable_if<true>::type
108
109
110// Names defined and accessed inside an inline namespace should be converted.
111// Whether or not the inline namespace is specified
112
113using InlineUnspecified = std::add_const<bool>::type;
114// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use c++14 style type templates
115// CHECK-FIXES: using InlineUnspecified = std::add_const_t<bool>;
116
117using Inline = std::__std_lib_version1::add_const<bool>::type;
118// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use c++14 style type templates
119// CHECK-FIXES: using Inline = std::__std_lib_version1::add_const_t<bool>;
120
121// Don't try to offer any fix if the name is an extension to the standard library
122using Ext = std::ext::add_const<bool>::type;
123
124namespace my_std = std;
125
126using Alias = my_std::add_const<bool>::type;
127// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use c++14 style type templates
128// CHECK-FIXES: using Alias = my_std::add_const_t<bool>;
129

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp