[PATCH] D102779: [clang-tidy] cppcoreguidelines-explicit-constructor-and-conversion: new alias
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 24 11:57:23 PDT 2021
aaron.ballman added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:22
+namespace {
+auto hasAnyWhitelistedName(const std::string &Names) {
+ const std::vector<std::string> NameList =
----------------
================
Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:23-24
+auto hasAnyWhitelistedName(const std::string &Names) {
+ const std::vector<std::string> NameList =
+ utils::options::parseStringList(Names);
+ return hasAnyName(std::vector<StringRef>(NameList.begin(), NameList.end()));
----------------
It's unfortunate that this is parsing the list of names each time -- I think we should parse the string list one time and pass a container in to this function rather than doing the split every time we encounter a constructor.
================
Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:102
if (const auto *Conversion =
- Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
+ Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
if (Conversion->isOutOfLine())
----------------
Unintended formatting change?
================
Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.h:28
+ : ClangTidyCheck(Name, Context),
+ ConstructorWhitelist(Options.get("ConstructorWhitelist", "")) {}
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
----------------
The community has recently been switching away from "whitelist" and "blacklist" terminology, so I'd recommend changing this to `IgnoredConstructors`.
Should conversion operators also have an allow list? (The core guideline doesn't mention it, but I'm wondering about code that wants an implicit conversion in a particular case and how they should silence the diagnostic in that case.)
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-constructorwhitelist-option.cpp:11
+// RUN: ]}'
+
+struct A {
----------------
It looks like there are no tests for conversion operators -- those should be added.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102779/new/
https://reviews.llvm.org/D102779
More information about the cfe-commits
mailing list