r192802 - Sema: Simplify the check if a method returns an instance of the class.
Benjamin Kramer
benny.kra at googlemail.com
Wed Oct 16 09:21:04 PDT 2013
Author: d0k
Date: Wed Oct 16 11:21:04 2013
New Revision: 192802
URL: http://llvm.org/viewvc/llvm-project?rev=192802&view=rev
Log:
Sema: Simplify the check if a method returns an instance of the class.
Just checking if the parent of the method is the same as the return type
should be sufficient. Also fixes PR17587.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-unused-result.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=192802&r1=192801&r2=192802&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Oct 16 11:21:04 2013
@@ -6911,7 +6911,9 @@ Sema::ActOnFunctionDeclarator(Scope *S,
if (!NewFD->isInvalidDecl() && !NewFD->hasAttr<WarnUnusedResultAttr>() &&
Ret && Ret->hasAttr<WarnUnusedResultAttr>()) {
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD);
- if (!(MD && MD->getCorrespondingMethodInClass(Ret, true))) {
+ // Attach the attribute to the new decl. Don't apply the attribute if it
+ // returns an instance of the class (e.g. assignment operators).
+ if (!MD || MD->getParent() != Ret) {
NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(),
Context));
}
Modified: cfe/trunk/test/SemaCXX/warn-unused-result.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-result.cpp?rev=192802&r1=192801&r2=192802&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-result.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-result.cpp Wed Oct 16 11:21:04 2013
@@ -78,3 +78,19 @@ void lazy() {
DoYetAnotherThing();
}
}
+
+namespace PR17587 {
+struct [[clang::warn_unused_result]] Status;
+
+struct Foo {
+ Status Bar();
+};
+
+struct Status {};
+
+void Bar() {
+ Foo f;
+ f.Bar(); // expected-warning {{ignoring return value}}
+};
+
+}
More information about the cfe-commits
mailing list