[PATCH] D17484: [clang-tidy] introduce modernize-deprecated-headers check
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 22 15:23:35 PST 2016
alexfh added inline comments.
================
Comment at: clang-tidy/modernize/DeprecatedHeadersCheck.cpp:78
@@ +77,3 @@
+ if (LangOpts.CPlusPlus11) {
+ std::vector<std::pair<std::string, std::string>> Cxx11DeprecatedHeaders = {
+ {"fenv.h", "cfenv"},
----------------
This can be done without STL algorithms and lambdas:
for (const auto &Pair : {{"fenv.h", "cfenv"}, ...})
CStyledHeaderToCxx.insert(Pair);
(didn't actually try this, so it might need some massaging, e.g. `std::pair<....>` instead of auto).
================
Comment at: clang-tidy/modernize/DeprecatedHeadersCheck.cpp:104
@@ +103,3 @@
+ if (CStyledHeaderToCxx.count(FileName) != 0) {
+ std::string Replacement = "<" + CStyledHeaderToCxx[FileName] + ">";
+ Check.diag(FilenameRange.getBegin(), "including deprecated C++ header")
----------------
A usual way to concatenate strings in LLVM is to use `llvm::Twine`:
std::string Replacement = (llvm::Twine("<") + ... + ...).str();
================
Comment at: clang-tidy/modernize/DeprecatedHeadersCheck.cpp:105
@@ +104,3 @@
+ std::string Replacement = "<" + CStyledHeaderToCxx[FileName] + ">";
+ Check.diag(FilenameRange.getBegin(), "including deprecated C++ header")
+ << FixItHint::CreateReplacement(FilenameRange.getAsRange(),
----------------
The message should name the header it complains about and suggest the replacement (in words, not only by attaching a fix. Something along the lines of:
"inclusion of a deprecated C++ header '%0'; consider including '%1' instead"
================
Comment at: test/clang-tidy/modernize-deprecated-headers-cxx03.cpp:32
@@ +31,3 @@
+
+// CHECK-MESSAGES: :[[@LINE-29]]:10: warning: including deprecated C++ header [modernize-deprecated-headers]
+// CHECK-MESSAGES: :[[@LINE-29]]:10: warning: including deprecated C++ header [modernize-deprecated-headers]
----------------
We usually specify each unique diagnostic message completely in one CHECK line and truncate repeated parts (e.g. the check name in brackets) in all other CHECK lines to make tests easier to read.
http://reviews.llvm.org/D17484
More information about the cfe-commits
mailing list