[clang-tools-extra] [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (PR #82689)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 23 08:44:17 PST 2024


================
@@ -130,18 +134,30 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
     return;
   }
 
-  if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor() ||
+  if (ExplicitSpec.isExplicit() || Ctor->isCopyOrMoveConstructor() ||
       TakesInitializerList)
     return;
 
+  // Don't complain about explicit(false)
+  const Expr *ExplicitExpr = ExplicitSpec.getExpr();
+  if (ExplicitExpr) {
+    ExplicitExpr = ExplicitExpr->IgnoreImplicit();
+    if (isa<CXXBoolLiteralExpr>(ExplicitExpr))
+      return;
+  }
+
----------------
5chmidti wrote:

I think that dependent expressions (`isInstantiationDependent`) should also be ignored, e.g.

```c++
template <int Val>
struct I {
  explicit(Val > 0) I(int);
};

template <int Val>
struct J {
  explicit(Val > 0) J(int);
};

void useJ(J<0>, J<100>);
```
should not produce any warnings IMO.

https://github.com/llvm/llvm-project/pull/82689


More information about the cfe-commits mailing list