[PATCH] D51332: Replace deprecated std::ios_base aliases
andobence created this revision. Herald added subscribers: cfe-commits, mgorny. This check warns the uses of the deprecated member types of std::ios_base and replaces those that have a non-deprecated equivalent. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51332 Files: clang-tidy/modernize/CMakeLists.txt clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.h clang-tidy/modernize/ModernizeTidyModule.cpp docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/modernize-deprecated-ios-base-aliases.rst test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp Index: test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp === --- /dev/null +++ test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp @@ -0,0 +1,240 @@ +// 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 { + 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' i
[PATCH] D51332: [clang-tidy] Replace deprecated std::ios_base aliases
andobence updated this revision to Diff 165453. andobence added a comment. Fixed everything mentioned in comments. https://reviews.llvm.org/D51332 Files: clang-tidy/modernize/CMakeLists.txt clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.h clang-tidy/modernize/ModernizeTidyModule.cpp docs/ReleaseNotes.rst docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/modernize-deprecated-ios-base-aliases.rst test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp Index: test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp === --- /dev/null +++ test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp @@ -0,0 +1,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 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 { + 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()}; + /
[PATCH] D51332: [clang-tidy] Replace deprecated std::ios_base aliases
andobence marked 2 inline comments as done. andobence added inline comments. Comment at: clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp:34 + // provide any benefit to other languages, despite being benign. + if (!getLangOpts().CPlusPlus) +return; JonasToth wrote: > Which standard supplies the replacement functionality? e.g. for C++98 the > warning is probably not relevant because there is no way to replace the > deprecated types, but for C++17 it is possible. C++98 already has them, these types has been deprecated since draft N0785 from 1995. https://reviews.llvm.org/D51332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51332: [clang-tidy] Replace deprecated std::ios_base aliases
andobence updated this revision to Diff 168452. andobence added a comment. Rebased on top of master. I don't have commit rights. https://reviews.llvm.org/D51332 Files: clang-tidy/modernize/CMakeLists.txt clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.h clang-tidy/modernize/ModernizeTidyModule.cpp docs/ReleaseNotes.rst docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/modernize-deprecated-ios-base-aliases.rst test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp Index: test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp === --- test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp +++ test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp @@ -0,0 +1,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 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 { + 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{}; +