1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
// RUN: %check_clang_tidy %s modernize-deprecated-ios-base-aliases %t
namespace std {
class ios_base {
public:
typedef int io_state;
typedef int open_mode;
typedef int seek_dir;
typedef int streampos;
typedef int streamoff;
};
template <class CharT>
class basic_ios : public ios_base {
};
} // namespace std
// Test function return values (declaration)
std::ios_base::io_state f_5();
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'std::ios_base::io_state' is deprecated; use 'std::ios_base::iostate' instead [modernize-deprecated-ios-base-aliases]
// CHECK-FIXES: std::ios_base::iostate f_5();
// Test function parameters.
void f_6(std::ios_base::open_mode);
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::open_mode' is deprecated
// CHECK-FIXES: void f_6(std::ios_base::openmode);
void f_7(const std::ios_base::seek_dir &);
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'std::ios_base::seek_dir' is deprecated
// CHECK-FIXES: void f_7(const std::ios_base::seekdir &);
// Test on record type fields.
struct A {
std::ios_base::io_state field;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate field;
typedef std::ios_base::io_state int_ptr_type;
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: typedef std::ios_base::iostate int_ptr_type;
};
struct B : public std::ios_base {
io_state a;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: iostate a;
};
struct C : public std::basic_ios<char> {
io_state a;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: iostate a;
};
void f_1() {
std::ios_base::io_state a;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate a;
// Check that spaces aren't modified unnecessarily.
std :: ios_base :: io_state b;
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std :: ios_base :: iostate b;
// Test construction from a temporary.
std::ios_base::io_state c = std::ios_base::io_state{};
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated
// CHECK-MESSAGES: :[[@LINE-2]]:46: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate c = std::ios_base::iostate{};
typedef std::ios_base::io_state alias1;
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: typedef std::ios_base::iostate alias1;
alias1 d(a);
using alias2 = std::ios_base::io_state;
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: using alias2 = std::ios_base::iostate;
alias2 e;
// Test pointers.
std::ios_base::io_state *f;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate *f;
// Test 'static' declarations.
static std::ios_base::io_state g;
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: static std::ios_base::iostate g;
// Test with cv-qualifiers.
const std::ios_base::io_state h(0);
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: const std::ios_base::iostate h(0);
volatile std::ios_base::io_state i;
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: volatile std::ios_base::iostate i;
const volatile std::ios_base::io_state j(0);
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: const volatile std::ios_base::iostate j(0);
// Test auto and initializer-list.
auto k = std::ios_base::io_state{};
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: auto k = std::ios_base::iostate{};
std::ios_base::io_state l{std::ios_base::io_state()};
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated
// CHECK-MESSAGES: :[[@LINE-2]]:44: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate l{std::ios_base::iostate()};
// Test temporaries.
std::ios_base::io_state();
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate();
// Test inherited type usage
std::basic_ios<char>::io_state m;
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::basic_ios<char>::iostate m;
std::ios_base::streampos n;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::streampos' is deprecated [modernize-deprecated-ios-base-aliases]
std::ios_base::streamoff o;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::streamoff' is deprecated [modernize-deprecated-ios-base-aliases]
}
// Test without the nested name specifiers.
void f_2() {
using namespace std;
ios_base::io_state a;
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: ios_base::iostate a;
}
// Test messing-up with macros.
void f_4() {
#define MACRO_1 std::ios_base::io_state
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: 'std::ios_base::io_state' is deprecated
MACRO_1 a;
#define MACRO_2 io_state
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'std::ios_base::io_state' is deprecated
std::ios_base::MACRO_2 b;
#define MACRO_3 std::ios_base
MACRO_3::io_state c;
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'std::ios_base::io_state' is deprecated
#define MACRO_4(type) type::io_state
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: 'std::ios_base::io_state' is deprecated
MACRO_4(std::ios_base) d;
#undef MACRO_1
#undef MACRO_2
#undef MACRO_3
#undef MACRO_4
}
// Test function return values (definition).
std::ios_base::io_state f_5()
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: std::ios_base::iostate f_5()
{
// Test constructor.
return std::ios_base::io_state(0);
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: return std::ios_base::iostate(0);
}
// Test that other aliases with same name aren't replaced
struct my_ios_base {
typedef int io_state;
};
namespace ns_1 {
struct my_ios_base2 {
typedef int io_state;
};
} // namespace ns_1
void f_8() {
my_ios_base::io_state a;
ns_1::my_ios_base2::io_state b;
}
// Test templates
template <typename X>
void f_9() {
typename std::basic_ios<X>::io_state p;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'std::ios_base::io_state' is deprecated
typename std::ios_base::io_state q;
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: typename std::ios_base::iostate q;
}
template <typename T>
void f_10(T arg) {
T x(arg);
}
template <typename T>
void f_11() {
typename T::io_state x{};
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'std::ios_base::io_state' is deprecated
}
template <typename T>
struct D : std::ios_base {
io_state a;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: iostate a;
typename std::basic_ios<T>::io_state b;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'std::ios_base::io_state' is deprecated
};
template <typename T>
struct E {
T t;
};
void f_12() {
f_9<char>();
f_10<std::ios_base::io_state>(0);
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: f_10<std::ios_base::iostate>(0);
f_11<std::ios_base>();
D<char> d;
E<std::ios_base::io_state> e;
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 'std::ios_base::io_state' is deprecated
// CHECK-FIXES: E<std::ios_base::iostate> e;
}
|