From c095b5361a5a8d949f42a5f6ce50b80254e88396 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Thu, 24 Dec 2009 00:28:18 +0000 Subject: [PATCH] support the warn_unused_result in C++ class methods llvm-svn: 92095 --- clang/lib/AST/Expr.cpp | 2 ++ clang/test/SemaCXX/warn-unused-variables.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index cb0165c8df7b..960d83d103a5 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -402,6 +402,8 @@ Decl *CallExpr::getCalleeDecl() { Expr *CEE = getCallee()->IgnoreParenCasts(); if (DeclRefExpr *DRE = dyn_cast(CEE)) return DRE->getDecl(); + if (MemberExpr *ME = dyn_cast(CEE)) + return ME->getMemberDecl(); return 0; } diff --git a/clang/test/SemaCXX/warn-unused-variables.cpp b/clang/test/SemaCXX/warn-unused-variables.cpp index 83a61bf8e007..5620248f5005 100644 --- a/clang/test/SemaCXX/warn-unused-variables.cpp +++ b/clang/test/SemaCXX/warn-unused-variables.cpp @@ -32,3 +32,14 @@ namespace PR5531 { C(); } } + + +struct X { + int foo() __attribute__((warn_unused_result)); +}; + +void bah() { + X x, *x2; + x.foo(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} + x2->foo(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} +}