Mercurial > hg > CbC > CbC_llvm
diff 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 |
line wrap: on
line diff
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp Wed Jul 21 10:27:27 2021 +0900 +++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp Wed Nov 09 17:45:10 2022 +0900 @@ -83,6 +83,20 @@ for (const auto *Arg : CE->arguments()) { markCanNotBeConst(Arg->IgnoreParenCasts(), true); } + // Data passed by nonconst reference should not be made const. + unsigned ArgNr = 0U; + if (const auto *CD = CE->getConstructor()) { + for (const auto *Par : CD->parameters()) { + if (ArgNr >= CE->getNumArgs()) + break; + const Expr *Arg = CE->getArg(ArgNr++); + // Is this a non constant reference parameter? + const Type *ParType = Par->getType().getTypePtr(); + if (!ParType->isReferenceType() || Par->getType().isConstQualified()) + continue; + markCanNotBeConst(Arg->IgnoreParenCasts(), false); + } + } } else if (const auto *R = dyn_cast<ReturnStmt>(S)) { markCanNotBeConst(R->getRetValue(), true); } else if (const auto *U = dyn_cast<UnaryOperator>(S)) { @@ -93,6 +107,9 @@ if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) || T->isArrayType()) markCanNotBeConst(VD->getInit(), true); + else if (T->isLValueReferenceType() && + !T->getPointeeType().isConstQualified()) + markCanNotBeConst(VD->getInit(), false); } }