forked from OSchip/llvm-project
Fix some places where PseudoObjectExpr handling assumed that a
PseudoObjectExpr is only used for ObjC properties and subscripts. For now, these assumptions are generally correct, but that's not part of the design of PseudoObjectExpr. No functionality change intended.
This commit is contained in:
parent
29f70e3e7d
commit
c7ecfadf9b
|
@ -2457,8 +2457,12 @@ bool Expr::isReadIfDiscardedInCPlusPlus11() const {
|
|||
}
|
||||
|
||||
// Objective-C++ extensions to the rule.
|
||||
if (isa<PseudoObjectExpr>(E) || isa<ObjCIvarRefExpr>(E))
|
||||
if (isa<ObjCIvarRefExpr>(E))
|
||||
return true;
|
||||
if (const auto *POE = dyn_cast<PseudoObjectExpr>(E)) {
|
||||
if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(POE->getSyntacticForm()))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -2708,23 +2712,35 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
|
|||
}
|
||||
|
||||
case ObjCPropertyRefExprClass:
|
||||
case ObjCSubscriptRefExprClass:
|
||||
WarnE = this;
|
||||
Loc = getExprLoc();
|
||||
R1 = getSourceRange();
|
||||
return true;
|
||||
|
||||
case PseudoObjectExprClass: {
|
||||
const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this);
|
||||
const auto *POE = cast<PseudoObjectExpr>(this);
|
||||
|
||||
// Only complain about things that have the form of a getter.
|
||||
if (isa<UnaryOperator>(PO->getSyntacticForm()) ||
|
||||
isa<BinaryOperator>(PO->getSyntacticForm()))
|
||||
return false;
|
||||
// For some syntactic forms, we should always warn.
|
||||
if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(
|
||||
POE->getSyntacticForm())) {
|
||||
WarnE = this;
|
||||
Loc = getExprLoc();
|
||||
R1 = getSourceRange();
|
||||
return true;
|
||||
}
|
||||
|
||||
WarnE = this;
|
||||
Loc = getExprLoc();
|
||||
R1 = getSourceRange();
|
||||
return true;
|
||||
// For others, we should never warn.
|
||||
if (auto *BO = dyn_cast<BinaryOperator>(POE->getSyntacticForm()))
|
||||
if (BO->isAssignmentOp())
|
||||
return false;
|
||||
if (auto *UO = dyn_cast<UnaryOperator>(POE->getSyntacticForm()))
|
||||
if (UO->isIncrementDecrementOp())
|
||||
return false;
|
||||
|
||||
// Otherwise, warn if the result expression would warn.
|
||||
const Expr *Result = POE->getResultExpr();
|
||||
return Result && Result->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
|
||||
}
|
||||
|
||||
case StmtExprClass: {
|
||||
|
|
|
@ -341,7 +341,7 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
|
|||
return DiagnoseUnusedExprResult(POE->getSemanticExpr(0), DiagID);
|
||||
if (isa<ObjCSubscriptRefExpr>(Source))
|
||||
DiagID = diag::warn_unused_container_subscript_expr;
|
||||
else
|
||||
else if (isa<ObjCPropertyRefExpr>(Source))
|
||||
DiagID = diag::warn_unused_property_expr;
|
||||
} else if (const CXXFunctionalCastExpr *FC
|
||||
= dyn_cast<CXXFunctionalCastExpr>(E)) {
|
||||
|
|
Loading…
Reference in New Issue