[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 6 23:38:12 PDT 2022
njames93 added a comment.
Why limit this to just the value type traits, makes sense to also support type type traits.
================
Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp:73
+ const auto *RecordQualifier =
+ cast_if_present<ClassTemplateSpecializationDecl>(
+ Qualifier->getAsRecordDecl());
----------------
Won't this assert if a pointer is supplied but it isn't a ClassTemplateSpecializationDefl. Wouldn't dyn_cast be needed.
In any case a test where you access a static variable from a non template class needs adding to make sure no warning is emitter.
================
Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp:82
+ auto IssuedDiag =
+ diag(MatchedDecl->getSourceRange().getEnd(), "C++11-style type trait");
+
----------------
Make the diagnostic a bit clearer.
================
Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp:86
+ auto CurrentText = tooling::fixit::getText(*MatchedDecl, *Result.Context);
+ if (replacement_regex.match(CurrentText))
+ IssuedDiag << FixItHint::CreateReplacement(
----------------
This fixit logic looks cumbersome, just replace the qualifier loc(::)to the declared with an `_v`. But only iff the qualified name loc is not a macro.
================
Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h:34
+private:
+ std::set<StringRef> ValueTypeTraits;
+};
----------------
We don't need an ordering here, so an llvm::DenseSet<StringRef> may be more suited here.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst:28
+
+.. option:: ValueTypeTraits
+
----------------
I'm not sure this option would ever be used in the wild as it would override all the default values in the stl.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135404/new/
https://reviews.llvm.org/D135404
More information about the cfe-commits
mailing list