[llvm-branch-commits] [clang-tools-extra] [clang-doc] Use explicit for single param constructors (PR #198068)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri May 15 23:57:22 PDT 2026


https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/198068

This trips up some clang-tidy checks, so add the explicit keyword as
needed to satisfy the lints.

>From dd01825ec17a9a4ec08aeb051b514064a094cbd3 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Sat, 16 May 2026 01:26:35 +0000
Subject: [PATCH] [clang-doc] Use explicit for single param constructors

This trips up some clang-tidy checks, so add the explicit keyword as
needed to satisfy the lints.
---
 clang-tools-extra/clang-doc/BitcodeWriter.cpp | 2 +-
 clang-tools-extra/clang-doc/ClangDoc.cpp      | 4 ++--
 clang-tools-extra/clang-doc/Serialize.cpp     | 2 +-
 clang-tools-extra/clang-doc/YAMLGenerator.cpp | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index cbd61b05c6e0a..f8431a44ec533 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -100,7 +100,7 @@ struct RecordIdDsc {
       : Name(Name), Abbrev(Abbrev) {}
 
   // Is this 'description' valid?
-  operator bool() const {
+  explicit operator bool() const {
     return Abbrev != nullptr && Name.data() != nullptr && !Name.empty();
   }
 
diff --git a/clang-tools-extra/clang-doc/ClangDoc.cpp b/clang-tools-extra/clang-doc/ClangDoc.cpp
index ec802d64fb609..7f5204f1e4d24 100644
--- a/clang-tools-extra/clang-doc/ClangDoc.cpp
+++ b/clang-tools-extra/clang-doc/ClangDoc.cpp
@@ -24,7 +24,7 @@ namespace doc {
 
 class MapperActionFactory : public tooling::FrontendActionFactory {
 public:
-  MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
+  explicit MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
   std::unique_ptr<FrontendAction> create() override;
 
 private:
@@ -34,7 +34,7 @@ class MapperActionFactory : public tooling::FrontendActionFactory {
 std::unique_ptr<FrontendAction> MapperActionFactory::create() {
   class ClangDocAction : public clang::ASTFrontendAction {
   public:
-    ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
+    explicit ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
 
     std::unique_ptr<clang::ASTConsumer>
     CreateASTConsumer(clang::CompilerInstance &Compiler,
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 1c8969b56441a..906bde99349cf 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -203,7 +203,7 @@ StringRef Serializer::getInfoRelativePath(const Decl *D) {
 class ClangDocCommentVisitor
     : public ConstCommentVisitor<ClangDocCommentVisitor> {
 public:
-  ClangDocCommentVisitor(CommentInfo &CI) : CurrentCI(CI) {}
+  explicit ClangDocCommentVisitor(CommentInfo &CI) : CurrentCI(CI) {}
 
   void parseComment(const comments::Comment *C);
 
diff --git a/clang-tools-extra/clang-doc/YAMLGenerator.cpp b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
index 0fe5cbad9bdaf..d08c695fd9756 100644
--- a/clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -198,8 +198,8 @@ template <> struct ScalarTraits<SymbolID> {
 struct QuotedString {
   StringRef Ref;
   QuotedString() = default;
-  QuotedString(StringRef R) : Ref(R) {}
-  operator StringRef() const { return Ref; }
+  explicit QuotedString(StringRef R) : Ref(R) {}
+  explicit operator StringRef() const { return Ref; }
   bool operator==(const QuotedString &Other) const { return Ref == Other.Ref; }
 };
 



More information about the llvm-branch-commits mailing list