comparison clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
81 } 81 }
82 } else if (const auto *CE = dyn_cast<CXXConstructExpr>(S)) { 82 } else if (const auto *CE = dyn_cast<CXXConstructExpr>(S)) {
83 for (const auto *Arg : CE->arguments()) { 83 for (const auto *Arg : CE->arguments()) {
84 markCanNotBeConst(Arg->IgnoreParenCasts(), true); 84 markCanNotBeConst(Arg->IgnoreParenCasts(), true);
85 } 85 }
86 // Data passed by nonconst reference should not be made const.
87 unsigned ArgNr = 0U;
88 if (const auto *CD = CE->getConstructor()) {
89 for (const auto *Par : CD->parameters()) {
90 if (ArgNr >= CE->getNumArgs())
91 break;
92 const Expr *Arg = CE->getArg(ArgNr++);
93 // Is this a non constant reference parameter?
94 const Type *ParType = Par->getType().getTypePtr();
95 if (!ParType->isReferenceType() || Par->getType().isConstQualified())
96 continue;
97 markCanNotBeConst(Arg->IgnoreParenCasts(), false);
98 }
99 }
86 } else if (const auto *R = dyn_cast<ReturnStmt>(S)) { 100 } else if (const auto *R = dyn_cast<ReturnStmt>(S)) {
87 markCanNotBeConst(R->getRetValue(), true); 101 markCanNotBeConst(R->getRetValue(), true);
88 } else if (const auto *U = dyn_cast<UnaryOperator>(S)) { 102 } else if (const auto *U = dyn_cast<UnaryOperator>(S)) {
89 markCanNotBeConst(U, true); 103 markCanNotBeConst(U, true);
90 } 104 }
91 } else if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("Mark")) { 105 } else if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("Mark")) {
92 const QualType T = VD->getType(); 106 const QualType T = VD->getType();
93 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) || 107 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
94 T->isArrayType()) 108 T->isArrayType())
95 markCanNotBeConst(VD->getInit(), true); 109 markCanNotBeConst(VD->getInit(), true);
110 else if (T->isLValueReferenceType() &&
111 !T->getPointeeType().isConstQualified())
112 markCanNotBeConst(VD->getInit(), false);
96 } 113 }
97 } 114 }
98 115
99 void NonConstParameterCheck::addParm(const ParmVarDecl *Parm) { 116 void NonConstParameterCheck::addParm(const ParmVarDecl *Parm) {
100 // Only add nonconst integer/float pointer parameters. 117 // Only add nonconst integer/float pointer parameters.