[clang-tools-extra] [clang-tidy] Fix false positives for dependent initializers (PR #186953)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 18 19:12:46 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) {
----------------
frank-suwen wrote:
Thanks for the suggestion!
I tried switching to the suggested range-based for loop using `PLE->exprs()`, but ran into an issue because `PLE` is a `const ParenListExpr*`, while `exprs()` does not appear to be a const-qualified member function. As a result, it could not be called in this situation.
Given this, I would like to double check what you would recommend here before proceeding:
- Should we keep the current index-based loop?
- Or is there a preferred way to iterate over `const ParenListExpr*`?
Happy to update accordingly. Thanks!
https://github.com/llvm/llvm-project/pull/186953
More information about the cfe-commits
mailing list