Index: include/clang/AST/ExprCXX.h =================================================================== --- include/clang/AST/ExprCXX.h +++ include/clang/AST/ExprCXX.h @@ -106,6 +106,16 @@ // operations on floating point types. bool isFPContractable() const { return FPContractable; } + // Check to see if a given overloaded operator is of assignment kind + static bool isAssignmentOp(OverloadedOperatorKind Opc) { + return Opc == OO_Equal || Opc == OO_StarEqual || + Opc == OO_SlashEqual || Opc == OO_PercentEqual || + Opc == OO_PlusEqual || Opc == OO_MinusEqual || + Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual || + Opc == OO_AmpEqual || Opc == OO_CaretEqual || + Opc == OO_PipeEqual; + } + friend class ASTStmtReader; friend class ASTStmtWriter; }; Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -2861,8 +2861,19 @@ // These never have a side-effect. return false; + case CXXOperatorCallExprClass: { + // When looking for potential side-effects, we assume that an overloaded + // assignment operator is intended to have a side-effect and other overloaded + // operators are not. + OverloadedOperatorKind Op = cast(this)->getOperator(); + if (CXXOperatorCallExpr::isAssignmentOp(Op)) { + const Decl *FD = cast(this)->getCalleeDecl(); + bool IsPure = FD && (FD->hasAttr() || FD->hasAttr()); + if (!IsPure) + return true; + } + } case CallExprClass: - case CXXOperatorCallExprClass: case CXXMemberCallExprClass: case CUDAKernelCallExprClass: case UserDefinedLiteralClass: {