brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.8 KiB · 680cb9e Raw
240 lines · cpp
1// RUN: %check_clang_tidy %s modernize-deprecated-ios-base-aliases %t2 3namespace std {4class ios_base {5public:6  typedef int io_state;7  typedef int open_mode;8  typedef int seek_dir;9 10  typedef int streampos;11  typedef int streamoff;12};13 14template <class CharT>15class basic_ios : public ios_base {16};17} // namespace std18 19// Test function return values (declaration)20std::ios_base::io_state f_5();21// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'std::ios_base::io_state' is deprecated; use 'std::ios_base::iostate' instead [modernize-deprecated-ios-base-aliases]22// CHECK-FIXES: std::ios_base::iostate f_5();23 24// Test function parameters.25void f_6(std::ios_base::open_mode);26// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::open_mode' is deprecated27// CHECK-FIXES: void f_6(std::ios_base::openmode);28void f_7(const std::ios_base::seek_dir &);29// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'std::ios_base::seek_dir' is deprecated30// CHECK-FIXES: void f_7(const std::ios_base::seekdir &);31 32// Test on record type fields.33struct A {34  std::ios_base::io_state field;35  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated36  // CHECK-FIXES: std::ios_base::iostate field;37 38  typedef std::ios_base::io_state int_ptr_type;39  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'std::ios_base::io_state' is deprecated40  // CHECK-FIXES: typedef std::ios_base::iostate int_ptr_type;41};42 43struct B : public std::ios_base {44  io_state a;45  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'std::ios_base::io_state' is deprecated46  // CHECK-FIXES: iostate a;47};48 49struct C : public std::basic_ios<char> {50  io_state a;51  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'std::ios_base::io_state' is deprecated52  // CHECK-FIXES: iostate a;53};54 55void f_1() {56  std::ios_base::io_state a;57  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated58  // CHECK-FIXES: std::ios_base::iostate a;59 60  // Check that spaces aren't modified unnecessarily.61  std :: ios_base :: io_state b;62  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'std::ios_base::io_state' is deprecated63  // CHECK-FIXES: std :: ios_base :: iostate b;64 65  // Test construction from a temporary.66  std::ios_base::io_state c = std::ios_base::io_state{};67  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated68  // CHECK-MESSAGES: :[[@LINE-2]]:46: warning: 'std::ios_base::io_state' is deprecated69  // CHECK-FIXES: std::ios_base::iostate c = std::ios_base::iostate{};70 71  typedef std::ios_base::io_state alias1;72  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'std::ios_base::io_state' is deprecated73  // CHECK-FIXES: typedef std::ios_base::iostate alias1;74  alias1 d(a);75 76  using alias2 = std::ios_base::io_state;77  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: 'std::ios_base::io_state' is deprecated78  // CHECK-FIXES: using alias2 = std::ios_base::iostate;79  alias2 e;80 81  // Test pointers.82  std::ios_base::io_state *f;83  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated84  // CHECK-FIXES: std::ios_base::iostate *f;85 86  // Test 'static' declarations.87  static std::ios_base::io_state g;88  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::io_state' is deprecated89  // CHECK-FIXES: static std::ios_base::iostate g;90 91  // Test with cv-qualifiers.92  const std::ios_base::io_state h(0);93  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'std::ios_base::io_state' is deprecated94  // CHECK-FIXES: const std::ios_base::iostate h(0);95  volatile std::ios_base::io_state i;96  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'std::ios_base::io_state' is deprecated97  // CHECK-FIXES: volatile std::ios_base::iostate i;98  const volatile std::ios_base::io_state j(0);99  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: 'std::ios_base::io_state' is deprecated100  // CHECK-FIXES: const volatile std::ios_base::iostate j(0);101 102  // Test auto and initializer-list.103  auto k = std::ios_base::io_state{};104  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'std::ios_base::io_state' is deprecated105  // CHECK-FIXES: auto k = std::ios_base::iostate{};106 107  std::ios_base::io_state l{std::ios_base::io_state()};108  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated109  // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: 'std::ios_base::io_state' is deprecated110  // CHECK-FIXES: std::ios_base::iostate l{std::ios_base::iostate()};111 112  // Test temporaries.113  std::ios_base::io_state();114  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::io_state' is deprecated115  // CHECK-FIXES: std::ios_base::iostate();116 117  // Test inherited type usage118  std::basic_ios<char>::io_state m;119  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::io_state' is deprecated120  // CHECK-FIXES: std::basic_ios<char>::iostate m;121 122  std::ios_base::streampos n;123  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::streampos' is deprecated [modernize-deprecated-ios-base-aliases]124 125  std::ios_base::streamoff o;126  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'std::ios_base::streamoff' is deprecated [modernize-deprecated-ios-base-aliases]127}128 129// Test without the nested name specifiers.130void f_2() {131  using namespace std;132 133  ios_base::io_state a;134  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'std::ios_base::io_state' is deprecated135  // CHECK-FIXES: ios_base::iostate a;136}137 138// Test messing-up with macros.139void f_4() {140#define MACRO_1 std::ios_base::io_state141  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: 'std::ios_base::io_state' is deprecated142  MACRO_1 a;143 144#define MACRO_2 io_state145  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'std::ios_base::io_state' is deprecated146  std::ios_base::MACRO_2 b;147 148#define MACRO_3 std::ios_base149  MACRO_3::io_state c;150  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'std::ios_base::io_state' is deprecated151 152#define MACRO_4(type) type::io_state153  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: 'std::ios_base::io_state' is deprecated154  MACRO_4(std::ios_base) d;155 156#undef MACRO_1157#undef MACRO_2158#undef MACRO_3159#undef MACRO_4160}161 162// Test function return values (definition).163std::ios_base::io_state f_5()164// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'std::ios_base::io_state' is deprecated165// CHECK-FIXES: std::ios_base::iostate f_5()166{167  // Test constructor.168  return std::ios_base::io_state(0);169  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 'std::ios_base::io_state' is deprecated170  // CHECK-FIXES: return std::ios_base::iostate(0);171}172 173// Test that other aliases with same name aren't replaced174struct my_ios_base {175  typedef int io_state;176};177 178namespace ns_1 {179struct my_ios_base2 {180  typedef int io_state;181};182} // namespace ns_1183 184void f_8() {185  my_ios_base::io_state a;186 187  ns_1::my_ios_base2::io_state b;188}189 190// Test templates191template <typename X>192void f_9() {193  typename std::basic_ios<X>::io_state p;194  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'std::ios_base::io_state' is deprecated195  typename std::ios_base::io_state q;196  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'std::ios_base::io_state' is deprecated197  // CHECK-FIXES: typename std::ios_base::iostate q;198}199 200template <typename T>201void f_10(T arg) {202  T x(arg);203}204 205template <typename T>206void f_11() {207  typename T::io_state x{};208  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'std::ios_base::io_state' is deprecated209}210 211template <typename T>212struct D : std::ios_base {213  io_state a;214  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'std::ios_base::io_state' is deprecated215  // CHECK-FIXES: iostate a;216 217  typename std::basic_ios<T>::io_state b;218  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'std::ios_base::io_state' is deprecated219};220 221template <typename T>222struct E {223  T t;224};225 226void f_12() {227  f_9<char>();228 229  f_10<std::ios_base::io_state>(0);230  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'std::ios_base::io_state' is deprecated231  // CHECK-FIXES: f_10<std::ios_base::iostate>(0);232 233  f_11<std::ios_base>();234  D<char> d;235 236  E<std::ios_base::io_state> e;237  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 'std::ios_base::io_state' is deprecated238  // CHECK-FIXES: E<std::ios_base::iostate> e;239}240