This patch introduces the modernize-deprecated-headers check, which is supposed to replace deprecated C library headers with the C++ STL-ones.
For information see documentation; for exmaples see the test cases.
Differential D17484
[clang-tidy] introduce modernize-deprecated-headers check omtcyf0 on Feb 20 2016, 11:14 AM. Authored by
Details This patch introduces the modernize-deprecated-headers check, which is supposed to replace deprecated C library headers with the C++ STL-ones. For information see documentation; for exmaples see the test cases.
Diff Detail Event TimelineComment Actions Thank you for implementing this check! However, I think will be good idea to always wrap header name in <> for warning and FixIt. Comment Actions Thanks for a review, Eugene! The FixItHint and warning now comes with the "angled" version of header wrapping. Comment Actions Other than a few nits, LGTM.
Comment Actions Another idea: to replace limits.h with limits and also replace its defines with their C++ counterparts. For example, INT_MIN with numeric_limits<int>::min(). Will be definitely useful for LLDB code modernization. Comment Actions Thanks for a review, Richard! Thanks for the hint, Eugene! Comment Actions Thank you for this check! Mostly looks good, but there are a number of style nits. The most important question to this check is that the standard doesn't guarantee that the C++ headers declare all the same functions in the global namespace (at least, this is how I understand the section of the standard you quoted). This means that the check in its current form can break the code that uses library symbols from the global namespace. The check could add std:: wherever it's needed (though it may be not completely trivial) to mitigate the risk. It's not what needs to be addressed in the first iteration, but it's definitely worth a look at in order to make the check actually useful. It also could be a separate check or a separate mode (configurable via parameters) of this check, while someone could have reasons to do the migration in two stages (add std:: qualifiers and then switch to new headers).
Comment Actions An action item for this is: document this possible issue and add a FIXME somewhere in the code to add std:: qualifiers. Comment Actions Oh crap, I totally forgot about this. Yes, I believe the weasel wording in the standard is that an implementation may put the symbols in the global namespace as well as inside std when the C++ header is used, but is not required to put them in the global namespace. They are required to put them in namespace std when the C++ header form is used. So if you switch to C++ headers, you code may still compile, but it is implementation dependent. If you use the C headers, you can't prefix symbols with std because they won't be there. In other discussions of this topic, it was considered best to make both changes at the same time: switch to the C++ header and decorate the symbols with std prefix. It would be reasonable for this check to insert a using namespace std; at the top of the translation unit after all the #include lines as a means of preserving meaning without trying to identify every symbol that needs std on it. Comment Actions Thank you for a review, Alex! I'll clean up the parts you mentioned soon! Yes, you are correct: the check might cause some troubles in codebases, because it is not guaranteed that the functions from the C library headers will occur in the global namespace. I was initially aware of that, but I thought it'd be better to add the initial check first and enhance it later. Appropriate FIXME seems great. I'm not sure that's a good option. I would certainly argue about putting using namespaces like std anywhere during the vanilla check run. Simply because of the collisions caused by some libraries with the functions having analogies in STL. However, I can see it as an option for the further variations of this check. Say, let it have three options:
just note for the future Seems quite sophisticated ATM though. Comment Actions Marked the comments as *done*.
Comment Actions Looks good with one nit. Let me know if you need me to commit the patch for you.
|
Is this header used?