[clang-tools-extra] [clang-tidy] Fix false positives for dependent initializers (PR #186953)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 22 00:22: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) {
+ const Expr *E = PLE->getExpr(I)->IgnoreParenCasts();
+ if (const auto *U = dyn_cast<UnaryOperator>(E);
+ U && U->getOpcode() == UO_Deref)
----------------
vbvictor wrote:
Deref is `*` IIRC, do we have tests with it?
https://github.com/llvm/llvm-project/pull/186953
More information about the cfe-commits
mailing list