This check will look for usages of standard library type traits of the form traits<...>::type and traits<...>::value and convert them into traits_t<...> and traits_v<...> respectively.
This expands on the work in D135404 by supporting dependent traits with no instantiations as well as types.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
---|---|---|
18 | Why do you refuse to use nested namespaces in modernize ? |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
---|---|---|
18 | Because the add_new_check script hasn't been updated since we went to c++17 |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
---|---|---|
18 | I think this is done for legacy reasons. This should be done for all checks and add_new_check.py. |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
141 | I don't see a reason why the naming convention can't be followed here? | |
143 | Why is an internal namespace needed, when you are already have the anonymous namespace? | |
144 | Internal functions and variables should be declared "static", outside the anonymous namespace, as per the LLVM Coding Standards. AST matchers can be put in the anonymous namespace. | |
182 | I think clang-format should remove these braces since it's only 1 statement in the "if" condition. | |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
31 | Nit: typically this is implemented inline in the header. | |
32 | There's an ongoing effort to deprecate llvm::Optional in favor of std::optional, perhaps start using it right away in this check? | |
clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp | ||
24 | Typo. Shouldn't the test have failed? |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
141 | Following the naming convention of the AST matchers, which all use camelBack | |
143 | I think it was because the matchers use an internal namespace, probably not need and can be removed. Let me check. | |
182 | As its more than 1 lines, keeping it in braces is cleaner. | |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
32 | This patch was last update before the switch, when the virtual function still returned an llvm::Optional, when I rebase it will need changing. | |
clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp | ||
24 | Good catch, it won't fail the test as filecheck will just ignore it. |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
17 | I'm guessing this list was obtained in some automatic way - could we document the process for generating it, so a future maintainer knows how to do it? | |
104 | Ditto | |
105–108 | Please keep alphabetical order. | |
134–139 | Why do we need these matchers at global scope, if they are only used in the registerMatchers function? Unless they are POD types, putting objects at global scope is bugprone since they are initialized before main in an unspecified order. | |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
18 | Is the goal to update all existing checks to C++17 format? | |
clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp | ||
38 | There should be a space in here, right? Same for the rest. | |
52 | As a user I find it a bit confusing that there is a warning, but no fix. Should we just disable the warning on macros entirely? Furthermore, the warning shows up at the call site, so if it's not possible to fix it will be very noisy for people to suppress it everywhere where the macro is used. Maybe add an option IgnoreMacros similar to how it's done for other checks? Alternatively, as a user I would like to be able to suppress the warning in line 54 once only instead of at the call site. |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
17 | They weren't, just copied from cppreference, I'm sure there is a way to automate it, but honestly there's not much point | |
105–108 | This is the order they appear on cppreference, so I think it makes sense to keep it like that, will make for an easier time maintaining this | |
134–139 | These are stateless matchers which require no construction, so there will be no initialisation order issues. They could be moved into the function that uses them without any issue though. | |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
18 | It should be done separately as an NFC change | |
clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp | ||
38 | I'm assuming you mean between <b> and inTemplate. | |
52 | I think IgnoreMacros is probably the best approach here, Getting warnings about marcos can be helpful if they are able to be fixed, but it would be nice to also silence those in cases when they can't. |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
173 | static not needed here, remove. I don't think LLVM guidelines enforce strict const correctness either so the const could be removed as well if wanted. | |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h | ||
18 | Sounds good, just want to make sure it's something we see value in fixing (as opposed to just being "churn"). I'm happy to put up an NFC patch for that! | |
clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp | ||
38 | I disagree, just because the code "compiles" it doesn't mean it's good. The only time I've seen code like this is in obfuscated code competitions :) We should not force the user to run clang-format to fix this - clang-tidy should preserve the existing space. This is not a matter of style either, it's a de-facto way of writting C++ (and many other languages): variable types and variable names in a declaration are separated by a space. |
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
173 | const correctness isn't enforced, but it doesn't harm | |
clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp | ||
38 | One of the original design decisions of clang-tidy was that check authors should not worry about formatting. This is partly because not everyone can agree on a style, but the main driving factor is that clang-tidy runs clang-format on the fixes that it generates unless you explicitly tell clang-tidy not to reformat your fixes. |
Remove unneeded static keyword
Improved fix-it logic if there is a space between the template name and the < token
Extend test cases to check inline namespace, extension namespaces and alias namespaces
LGTM, really useful check! Would be nice to get some more eyes on the implementation, it's fairly advanced for my basic AST knowledge.
Looks good to me - looking forward to this check!
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | ||
---|---|---|
171 | NIT: should the bound node have some meaningful non-empty name? | |
198 | For a future release, could we add an option to allow replacing "standard type traits" defined in separate namespaces, as the BSL library does? This would be useful in my case at least. |
Why do you refuse to use nested namespaces in modernize ?