aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaelyn Uhrain <rikka@google.com>2012-11-13 21:23:31 +0000
committerKaelyn Uhrain <rikka@google.com>2012-11-13 21:23:31 +0000
commit97c81bfaf0b6c90576081c5af7ea22fab6f2b7f9 (patch)
treee2436064a2938d7eef35395fa7fe83e3b4f0a188
parent2ccecfaa4852c134191d4075d94e09399ab46fea (diff)
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167873 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp6
-rw-r--r--test/SemaCXX/warn-unused-result.cpp6
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index f2e840494f..04f66e5882 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/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<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) {
diff --git a/test/SemaCXX/warn-unused-result.cpp b/test/SemaCXX/warn-unused-result.cpp
index 5ce0f98bc4..b0bf61f381 100644
--- a/test/SemaCXX/warn-unused-result.cpp
+++ b/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();