From 2fb89539f78cbb567253dbbb2fb1acb61583867c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sun, 21 Feb 2010 05:15:32 +0000 Subject: [PATCH] Clang really intends to reject attribute 'warn_unused_result' on Objective-C methods, but instead it crashes on them. We might extend this attribute to work on methods, but for now fix the crasher. Addresses . llvm-svn: 96723 --- clang/lib/Sema/SemaDeclAttr.cpp | 2 +- clang/test/SemaObjC/method-warn-unused-attribute.m | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaObjC/method-warn-unused-attribute.m diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index ef82d53b5c78..8178a147513b 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -754,7 +754,7 @@ static void HandleWarnUnusedResult(Decl *D, const AttributeList &Attr, Sema &S) return; } - if (!isFunctionOrMethod(D)) { + if (!isFunction(D)) { S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << Attr.getName() << 0 /*function*/; return; diff --git a/clang/test/SemaObjC/method-warn-unused-attribute.m b/clang/test/SemaObjC/method-warn-unused-attribute.m new file mode 100644 index 000000000000..d9dcf996ecb2 --- /dev/null +++ b/clang/test/SemaObjC/method-warn-unused-attribute.m @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s + +@interface INTF +// Currently this is rejected by both GCC and Clang (and Clang was crashing on it). +- (id) foo __attribute__((warn_unused_result)); // expected-warning{{warning: 'warn_unused_result' attribute only applies to function types}} +@end + +