[clang-tools-extra] [clang-tidy] Fix false positives for dependent initializers (PR #186953)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 14 21:56:52 PDT 2026


================
@@ -103,14 +103,31 @@ void NonConstParameterCheck::check(const MatchFinder::MatchResult &Result) {
     }
   } else if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("Mark")) {
     const QualType T = VD->getType();
-    if (T->isDependentType())
-      markCanNotBeConst(VD->getInit(), false);
-    else if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-             T->isArrayType() || T->isRecordType())
+    if (T->isDependentType()) {
+      const Expr *Init = VD->getInit()->IgnoreParenCasts();
+      if (const auto *U = dyn_cast<UnaryOperator>(Init);
+          U && U->getOpcode() == UO_Deref) {
+        markCanNotBeConst(U->getSubExpr(), true);
+      } else if (const auto *PLE = dyn_cast<ParenListExpr>(Init)) {
+        for (unsigned I = 0; I < PLE->getNumExprs(); ++I) {
----------------
zwuis wrote:

```cpp
for (const Expr *E /* or other name */ : PLE->exprs())
```

Use range-based `for`.

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


More information about the cfe-commits mailing list