Kaydet (Commit) f9889a69 authored tarafından Noel Grandin's avatar Noel Grandin

check for field being returned by non-const ref

Change-Id: I660c98dcbfa6052628ff667886981d075f34b2b7
üst e4b33235
......@@ -190,7 +190,8 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
if (ignoreLocation(memberExpr) || !isInterestingType(fieldDecl->getType()))
return true;
const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(get_top_FunctionDecl_from_Stmt(*memberExpr));
const FunctionDecl* parentFunctionDecl = get_top_FunctionDecl_from_Stmt(*memberExpr);
const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(parentFunctionDecl);
if (methodDecl && (methodDecl->isCopyAssignmentOperator() || methodDecl->isMoveAssignmentOperator()))
return true;
......@@ -200,7 +201,20 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
bool bPotentiallyAssignedTo = false;
bool bDump = false;
std::string assignValue;
do {
// check for field being returned by non-const ref eg. Foo& getFoo() { return f; }
if (parent && isa<ReturnStmt>(parent)) {
const Stmt* parent2 = parentStmt(parent);
if (parent2 && isa<CompoundStmt>(parent2)) {
QualType qt = parentFunctionDecl->getReturnType().getDesugaredType(compiler.getASTContext());
if (!qt.isConstQualified() && qt->isReferenceType()) {
assignValue = "?";
bPotentiallyAssignedTo = true;
}
}
}
while (!bPotentiallyAssignedTo) {
// check for field being accessed by a reference variable e.g. Foo& f = m.foo;
auto parentsList = compiler.getASTContext().getParents(*child);
auto it = parentsList.begin();
......@@ -303,7 +317,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
bDump = true;
break;
}
} while (true);
}
if (bDump)
{
report(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment