Debian Codegraph @

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

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