From: Kaelyn Uhrain Date: Tue, 13 Nov 2012 21:23:31 +0000 (+0000) Subject: For classes that have the warn_unused_result attribute, don't apply the X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1137001938500c8939b800fa2cc04d40d6968fb4;p=platform%2Fupstream%2Fllvm.git For classes that have the warn_unused_result attribute, don't apply the attribute to the class' methods even when they return an instance of the class (e.g. assignment operators). llvm-svn: 167873 --- diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f2e8404..04f66e5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5696,7 +5696,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, RetType->getAsCXXRecordDecl() : RetType->getPointeeCXXRecordDecl(); if (!NewFD->isInvalidDecl() && !NewFD->hasAttr() && Ret && Ret->hasAttr()) { - NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(), Context)); + const CXXMethodDecl *MD = dyn_cast(NewFD); + if (!(MD && MD->getCorrespondingMethodInClass(Ret, true))) { + NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(), + Context)); + } } if (!getLangOpts().CPlusPlus) { diff --git a/clang/test/SemaCXX/warn-unused-result.cpp b/clang/test/SemaCXX/warn-unused-result.cpp index 5ce0f98..b0bf61f 100644 --- a/clang/test/SemaCXX/warn-unused-result.cpp +++ b/clang/test/SemaCXX/warn-unused-result.cpp @@ -46,6 +46,12 @@ void bah() { 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();