mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-25 07:38:33 -05:00
clang-tidy module: add tests for cmsys::fstream check
Co-Authored-by: Kyle Edwards <kyle.edwards@kitware.com>
This commit is contained in:
committed by
Kyle Edwards
parent
d520853682
commit
ffa970559c
@@ -11,3 +11,4 @@ function(add_run_clang_tidy_test check_name)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
add_run_clang_tidy_test(cmake-use-cmstrlen)
|
add_run_clang_tidy_test(cmake-use-cmstrlen)
|
||||||
|
add_run_clang_tidy_test(cmake-use-cmsys-fstream)
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace cmsys {
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ns {
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
|
||||||
|
namespace ns {
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
class cl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using ifstream = cmsys::ifstream;
|
||||||
|
using ofstream = cmsys::ofstream;
|
||||||
|
using fstream = cmsys::fstream;
|
||||||
|
};
|
||||||
|
|
||||||
|
using ifs = cmsys::ifstream;
|
||||||
|
using ofs = cmsys::ofstream;
|
||||||
|
using fs = cmsys::fstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
|
||||||
|
// Correction needed
|
||||||
|
cmsys::ifstream ifsUnqual;
|
||||||
|
cmsys::ifstream ifsQual;
|
||||||
|
cmsys::ifstream ifsNS;
|
||||||
|
cmsys::ifstream ifsNested;
|
||||||
|
cmsys::ifstream ifsClass;
|
||||||
|
cmsys::ifstream ifsRenamed;
|
||||||
|
|
||||||
|
cmsys::ofstream ofsUnqual;
|
||||||
|
cmsys::ofstream ofsQual;
|
||||||
|
cmsys::ofstream ofsNS;
|
||||||
|
cmsys::ofstream ofsNested;
|
||||||
|
cmsys::ofstream ofsClass;
|
||||||
|
cmsys::ofstream ofsRenamed;
|
||||||
|
|
||||||
|
cmsys::fstream fsUnqual;
|
||||||
|
cmsys::fstream fsQual;
|
||||||
|
cmsys::fstream fsNS;
|
||||||
|
cmsys::fstream fsNested;
|
||||||
|
cmsys::fstream fsClass;
|
||||||
|
cmsys::fstream fsRenamed;
|
||||||
|
|
||||||
|
cmsys::ifstream::off_type offsetQual = 0;
|
||||||
|
cmsys::ifstream::off_type offsetUnqual = 0;
|
||||||
|
cmsys::ifstream::off_type offsetNS = 0;
|
||||||
|
cmsys::ifstream::off_type offsetNested = 0;
|
||||||
|
cmsys::ifstream::traits_type::off_type offsetTraitsNested = 0;
|
||||||
|
cmsys::ifstream::traits_type::off_type offsetTraitsClass = 0;
|
||||||
|
|
||||||
|
std::vector<cmsys::ifstream> ifsVectorUnqual;
|
||||||
|
|
||||||
|
// No correction needed
|
||||||
|
cmsys::ifstream ifsCmsys;
|
||||||
|
cmsys::ofstream ofsCmsys;
|
||||||
|
cmsys::fstream fsCmsys;
|
||||||
|
cmsys::ifstream::off_type offsetCmsys = 0;
|
||||||
|
cmsys::ifstream::traits_type::off_type offsetTraitsCmsys = 0;
|
||||||
|
std::vector<cmsys::ifstream> ifsVectorCmsys;
|
||||||
|
std::basic_ifstream<wchar_t> ifsWchar;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
cmake-use-cmsys-fstream.cxx:24:20: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
using ifstream = std::ifstream;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:24:20: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:25:20: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
using ofstream = std::ofstream;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:25:20: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:26:19: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
using fstream = std::fstream;
|
||||||
|
^~~~~~~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:26:19: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:29:13: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
using ifs = std::ifstream;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:29:13: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:30:13: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
using ofs = std::ofstream;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:30:13: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:31:12: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
using fs = std::fstream;
|
||||||
|
^~~~~~~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:31:12: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:41:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ifstream ifsUnqual;
|
||||||
|
^~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:41:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:42:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
std::ifstream ifsQual;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:42:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:43:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ifstream ifsNS;
|
||||||
|
^~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:43:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:44:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ns::ifstream ifsNested;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:44:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:45:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::cl::ifstream ifsClass;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:45:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:46:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ifs ifsRenamed;
|
||||||
|
^~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:46:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:48:3: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
ofstream ofsUnqual;
|
||||||
|
^~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:48:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:49:3: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
std::ofstream ofsQual;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:49:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:50:3: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ofstream ofsNS;
|
||||||
|
^~~~~~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:50:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:51:3: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ns::ofstream ofsNested;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:51:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:52:3: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::cl::ofstream ofsClass;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:52:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:53:3: warning: use cmsys::ofstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ofs ofsRenamed;
|
||||||
|
^~~~~~~
|
||||||
|
cmsys::ofstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:53:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:55:3: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
fstream fsUnqual;
|
||||||
|
^~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:55:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:56:3: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
std::fstream fsQual;
|
||||||
|
^~~~~~~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:56:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:57:3: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::fstream fsNS;
|
||||||
|
^~~~~~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:57:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:58:3: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ns::fstream fsNested;
|
||||||
|
^~~~~~~~~~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:58:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:59:3: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ns::fstream fsClass;
|
||||||
|
^~~~~~~~~~~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:59:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:60:3: warning: use cmsys::fstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::fs fsRenamed;
|
||||||
|
^~~~~~
|
||||||
|
cmsys::fstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:60:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:62:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
std::ifstream::off_type offsetQual = 0;
|
||||||
|
^~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:62:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:63:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ifstream::off_type offsetUnqual = 0;
|
||||||
|
^~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:63:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:64:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ifstream::off_type offsetNS = 0;
|
||||||
|
^~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:64:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:65:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ns::ifstream::off_type offsetNested = 0;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:65:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:66:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::ns::ifstream::traits_type::off_type offsetTraitsNested = 0;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:66:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:67:3: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
ns::cl::ifstream::traits_type::off_type offsetTraitsClass = 0;
|
||||||
|
^~~~~~~~~~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:67:3: note: FIX-IT applied suggested code changes
|
||||||
|
cmake-use-cmsys-fstream.cxx:69:15: warning: use cmsys::ifstream [cmake-use-cmsys-fstream]
|
||||||
|
std::vector<ifstream> ifsVectorUnqual;
|
||||||
|
^~~~~~~~
|
||||||
|
cmsys::ifstream
|
||||||
|
cmake-use-cmsys-fstream.cxx:69:15: note: FIX-IT applied suggested code changes
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace cmsys {
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ns {
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
|
||||||
|
namespace ns {
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
class cl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using ifstream = std::ifstream;
|
||||||
|
using ofstream = std::ofstream;
|
||||||
|
using fstream = std::fstream;
|
||||||
|
};
|
||||||
|
|
||||||
|
using ifs = std::ifstream;
|
||||||
|
using ofs = std::ofstream;
|
||||||
|
using fs = std::fstream;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using std::ifstream;
|
||||||
|
using std::ofstream;
|
||||||
|
using std::fstream;
|
||||||
|
|
||||||
|
// Correction needed
|
||||||
|
ifstream ifsUnqual;
|
||||||
|
std::ifstream ifsQual;
|
||||||
|
ns::ifstream ifsNS;
|
||||||
|
ns::ns::ifstream ifsNested;
|
||||||
|
ns::cl::ifstream ifsClass;
|
||||||
|
ns::ifs ifsRenamed;
|
||||||
|
|
||||||
|
ofstream ofsUnqual;
|
||||||
|
std::ofstream ofsQual;
|
||||||
|
ns::ofstream ofsNS;
|
||||||
|
ns::ns::ofstream ofsNested;
|
||||||
|
ns::cl::ofstream ofsClass;
|
||||||
|
ns::ofs ofsRenamed;
|
||||||
|
|
||||||
|
fstream fsUnqual;
|
||||||
|
std::fstream fsQual;
|
||||||
|
ns::fstream fsNS;
|
||||||
|
ns::ns::fstream fsNested;
|
||||||
|
ns::ns::fstream fsClass;
|
||||||
|
ns::fs fsRenamed;
|
||||||
|
|
||||||
|
std::ifstream::off_type offsetQual = 0;
|
||||||
|
ifstream::off_type offsetUnqual = 0;
|
||||||
|
ns::ifstream::off_type offsetNS = 0;
|
||||||
|
ns::ns::ifstream::off_type offsetNested = 0;
|
||||||
|
ns::ns::ifstream::traits_type::off_type offsetTraitsNested = 0;
|
||||||
|
ns::cl::ifstream::traits_type::off_type offsetTraitsClass = 0;
|
||||||
|
|
||||||
|
std::vector<ifstream> ifsVectorUnqual;
|
||||||
|
|
||||||
|
// No correction needed
|
||||||
|
cmsys::ifstream ifsCmsys;
|
||||||
|
cmsys::ofstream ofsCmsys;
|
||||||
|
cmsys::fstream fsCmsys;
|
||||||
|
cmsys::ifstream::off_type offsetCmsys = 0;
|
||||||
|
cmsys::ifstream::traits_type::off_type offsetTraitsCmsys = 0;
|
||||||
|
std::vector<cmsys::ifstream> ifsVectorCmsys;
|
||||||
|
std::basic_ifstream<wchar_t> ifsWchar;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user