attribute to the class' methods even when they return an instance of the
class (e.g. assignment operators).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167873
91177308-0d34-0410-b5e6-
96231b3b80d8
RetType->getAsCXXRecordDecl() : RetType->getPointeeCXXRecordDecl();
if (!NewFD->isInvalidDecl() && !NewFD->hasAttr<WarnUnusedResultAttr>() &&
Ret && Ret->hasAttr<WarnUnusedResultAttr>()) {
- NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(), Context));
+ const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD);
+ if (!(MD && MD->getCorrespondingMethodInClass(Ret, true))) {
+ NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(),
+ Context));
+ }
}
if (!getLangOpts().CPlusPlus) {
namespace warn_unused_CXX11 {
struct [[clang::warn_unused_result]] Status {
bool ok() const;
+ Status& operator=(const Status& x);
+ inline void Update(const Status& new_status) {
+ if (ok()) {
+ *this = new_status; //no-warning
+ }
+ }
};
Status DoSomething();
Status& DoSomethingElse();