|
| 1 | +// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s readability-redundant-typename %t \ |
| 2 | +// RUN: -- -- -fno-delayed-template-parsing |
| 3 | +// RUN: %check_clang_tidy -std=c++20-or-later -check-suffixes=,20 %s readability-redundant-typename %t \ |
| 4 | +// RUN: -- -- -fno-delayed-template-parsing |
| 5 | + |
| 6 | +struct NotDependent { |
| 7 | + using R = int; |
| 8 | +}; |
| 9 | + |
| 10 | +auto f(typename NotDependent::R) |
| 11 | + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant 'typename' [readability-redundant-typename] |
| 12 | + // CHECK-FIXES: auto f(NotDependent::R) |
| 13 | + -> typename NotDependent::R |
| 14 | + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant 'typename' [readability-redundant-typename] |
| 15 | + // CHECK-FIXES: -> NotDependent::R |
| 16 | +{ |
| 17 | + return typename NotDependent::R(); |
| 18 | + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant 'typename' [readability-redundant-typename] |
| 19 | + // return NotDependent::R(); |
| 20 | +} |
| 21 | + |
| 22 | +template < |
| 23 | + typename T, |
| 24 | + typename T::R V, |
| 25 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename] |
| 26 | + // CHECK-FIXES-20: T::R V, |
| 27 | + typename U = typename T::R |
| 28 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:16: warning: redundant 'typename' [readability-redundant-typename] |
| 29 | + // CHECK-FIXES-20: typename U = T::R |
| 30 | +> |
| 31 | +auto f() -> typename T::R |
| 32 | +// CHECK-MESSAGES-20: :[[@LINE-1]]:13: warning: redundant 'typename' [readability-redundant-typename] |
| 33 | +// CHECK-FIXES-20: auto f() -> T::R |
| 34 | +{ |
| 35 | + static_cast<typename T::R>(0); |
| 36 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:15: warning: redundant 'typename' [readability-redundant-typename] |
| 37 | + // CHECK-FIXES-20: static_cast<T::R>(0); |
| 38 | + |
| 39 | + dynamic_cast<typename T::R>(0); |
| 40 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:16: warning: redundant 'typename' [readability-redundant-typename] |
| 41 | + // CHECK-FIXES-20: dynamic_cast<T::R>(0); |
| 42 | + |
| 43 | + reinterpret_cast<typename T::R>(0); |
| 44 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:20: warning: redundant 'typename' [readability-redundant-typename] |
| 45 | + // CHECK-FIXES-20: reinterpret_cast<T::R>(0); |
| 46 | + |
| 47 | + const_cast<typename T::R>(0); |
| 48 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:14: warning: redundant 'typename' [readability-redundant-typename] |
| 49 | + // CHECK-FIXES-20: const_cast<T::R>(0); |
| 50 | + |
| 51 | + static_cast<typename T::R&>(0); |
| 52 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:15: warning: redundant 'typename' [readability-redundant-typename] |
| 53 | + // CHECK-FIXES-20: static_cast<T::R&>(0); |
| 54 | + |
| 55 | + dynamic_cast<typename T::R const volatile &&>(0); |
| 56 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:16: warning: redundant 'typename' [readability-redundant-typename] |
| 57 | + // CHECK-FIXES-20: dynamic_cast<T::R const volatile &&>(0); |
| 58 | + |
| 59 | + reinterpret_cast<const typename T::template M<42>::R *>(0); |
| 60 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:26: warning: redundant 'typename' [readability-redundant-typename] |
| 61 | + // CHECK-FIXES-20: reinterpret_cast<const T::template M<42>::R *>(0); |
| 62 | + |
| 63 | + const_cast<const typename T::R *const[100]>(0); |
| 64 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:20: warning: redundant 'typename' [readability-redundant-typename] |
| 65 | + // CHECK-FIXES-20: const_cast<const T::R *const[100]>(0); |
| 66 | + |
| 67 | + (typename T::R)(0); |
| 68 | + |
| 69 | + alignof(typename T::R); |
| 70 | + |
| 71 | + new typename T::R(); |
| 72 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:7: warning: redundant 'typename' [readability-redundant-typename] |
| 73 | + // CHECK-FIXES-20: new T::R(); |
| 74 | + |
| 75 | + // CHECK-MESSAGES-20: :[[@LINE+2]]:15: warning: redundant 'typename' [readability-redundant-typename] |
| 76 | + // CHECK-FIXES-20: static_cast<decltype([] { |
| 77 | + static_cast<typename decltype([] { |
| 78 | + return typename T::R(); // Inner typename must stay. |
| 79 | + })::R>(0); |
| 80 | + |
| 81 | + auto localFunctionDeclaration() -> typename T::R; |
| 82 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:38: warning: redundant 'typename' [readability-redundant-typename] |
| 83 | + // CHECK-FIXES-20: auto localFunctionDeclaration() -> T::R; |
| 84 | + |
| 85 | + void (*PointerToFunction)(typename T::R); |
| 86 | + void anotherLocalFunctionDeclaration(typename T::R); |
| 87 | + |
| 88 | + typename T::R DependentVar; |
| 89 | + typename NotDependent::R NotDependentVar; |
| 90 | + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename] |
| 91 | + // CHECK-FIXES: NotDependent::R NotDependentVar; |
| 92 | + |
| 93 | + return typename T::R(); |
| 94 | +} |
| 95 | + |
| 96 | +template <typename T> |
| 97 | +using trait = const typename T::R ****; |
| 98 | +// CHECK-MESSAGES-20: :[[@LINE-1]]:21: warning: redundant 'typename' [readability-redundant-typename] |
| 99 | +// CHECK-FIXES-20: using trait = const T::R ****; |
| 100 | + |
| 101 | +template <typename T> |
| 102 | +trait<typename T::R> m(); |
| 103 | + |
| 104 | +#if __cplusplus >= 202002L |
| 105 | + |
| 106 | +template <typename T> |
| 107 | +concept c = requires(typename T::R) { |
| 108 | +// CHECK-MESSAGES-20: :[[@LINE-1]]:22: warning: redundant 'typename' [readability-redundant-typename] |
| 109 | +// CHECK-FIXES-20: concept c = requires(T::R) { |
| 110 | + typename T::R; |
| 111 | +}; |
| 112 | + |
| 113 | +template <typename T> |
| 114 | +requires c<typename T::R> |
| 115 | +void b(); |
| 116 | + |
| 117 | +#endif // __cplusplus >= 202002L |
| 118 | + |
| 119 | +template <typename T, typename> |
| 120 | +struct PartiallySpecializedType {}; |
| 121 | + |
| 122 | +template <typename T> |
| 123 | +struct PartiallySpecializedType<T, typename T::R> {}; |
| 124 | + |
| 125 | +template <typename T> |
| 126 | +auto v = typename T::type(); |
| 127 | + |
| 128 | +template <typename T> |
| 129 | +typename T::R f(); |
| 130 | +// CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' [readability-redundant-typename] |
| 131 | +// CHECK-FIXES-20: T::R f(); |
| 132 | + |
| 133 | +template <typename T> |
| 134 | +void n(typename T::R); |
| 135 | + |
| 136 | +namespace ns { |
| 137 | + |
| 138 | +template <typename T> |
| 139 | +void f(typename T::R1, typename T::R2); |
| 140 | + |
| 141 | +} // namespace ns |
| 142 | + |
| 143 | +template <typename T> |
| 144 | +void ns::f( |
| 145 | + typename T::R1, |
| 146 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename] |
| 147 | + // CHECK-FIXES-20: T::R1, |
| 148 | + typename T::R2 |
| 149 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename] |
| 150 | + // CHECK-FIXES-20: T::R2 |
| 151 | +); |
| 152 | + |
| 153 | +template <typename T> |
| 154 | +class A { |
| 155 | +public: |
| 156 | + friend typename T::R; |
| 157 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:10: warning: redundant 'typename' [readability-redundant-typename] |
| 158 | + // CHECK-FIXES-20: friend T::R; |
| 159 | + |
| 160 | + typedef typename T::R a; |
| 161 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:11: warning: redundant 'typename' [readability-redundant-typename] |
| 162 | + // CHECK-FIXES-20: typedef T::R a; |
| 163 | + |
| 164 | + const typename T::R typedef b; |
| 165 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:9: warning: redundant 'typename' [readability-redundant-typename] |
| 166 | + // CHECK-FIXES-20: const T::R typedef b; |
| 167 | + |
| 168 | + typename T::R v; |
| 169 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename] |
| 170 | + // CHECK-FIXES-20: T::R v; |
| 171 | + |
| 172 | + typename T::R |
| 173 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename] |
| 174 | + // CHECK-FIXES-20: T::R |
| 175 | + g(typename T::R) {} |
| 176 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:5: warning: redundant 'typename' [readability-redundant-typename] |
| 177 | + // CHECK-FIXES-20: g(T::R) {} |
| 178 | + |
| 179 | + void h(typename T::R = typename T::R()) {} |
| 180 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:10: warning: redundant 'typename' [readability-redundant-typename] |
| 181 | + // CHECK-FIXES-20: void h(T::R = typename T::R()) {} |
| 182 | + |
| 183 | + friend void k(typename T::R) {} |
| 184 | + // CHECK-MESSAGES-20: :[[@LINE-1]]:17: warning: redundant 'typename' [readability-redundant-typename] |
| 185 | + // CHECK-FIXES-20: friend void k(T::R) {} |
| 186 | + |
| 187 | + enum E1 : typename T::R {}; |
| 188 | + enum class E2 : typename T::R {}; |
| 189 | + operator typename T::R(); |
| 190 | + void m() { this->operator typename T::R(); } |
| 191 | +}; |
0 commit comments