modocache created this revision.
modocache added a reviewer: cfe-commits.

Depends on http://reviews.llvm.org/D12047.

Add a unit test which demonstrates the bug reported in
https://llvm.org/bugs/show_bug.cgi?id=24404.

If the macro is enclosed within parentheses, the warning is reported as
expected. Without parentheses, no warning is emitted--this is a bug.

http://reviews.llvm.org/D12048

Files:
  test/SemaObjC/access-property-getter.m

Index: test/SemaObjC/access-property-getter.m
===================================================================
--- test/SemaObjC/access-property-getter.m
+++ test/SemaObjC/access-property-getter.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -fblocks -verify %s
 
 @protocol Protocol
 - (oneway void) method;
@@ -9,9 +9,27 @@
 }
 
 // rdar://19137815
+#pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-getter-return-value"
 
 void 
accessMethodViaPropertySyntaxWhenWarningIsIgnoredDoesNotTriggerWarning(id<Protocol>
 object) {
     object.method;
 }
 
+#pragma clang diagnostic pop
+
+@protocol ProtocolWithBlockProperty
+@property (readonly) void (^blockProperty)(void);
+@end
+
+id<ProtocolWithBlockProperty> protocolWithBlockPropertyConstructor(void);
+#define protocolWithBlockPropertyConstructorMacro 
protocolWithBlockPropertyConstructor
+
+void accessBlockPropertyDoesNotTriggerWarning(void) {
+    protocolWithBlockPropertyConstructorMacro().blockProperty;
+}
+
+void accessBlockPropertyInParenthesesTriggersWarning(void) {
+    (protocolWithBlockPropertyConstructorMacro()).blockProperty; // 
expected-warning {{property access result unused - getters should not be used 
for side effects}}
+}
+


Index: test/SemaObjC/access-property-getter.m
===================================================================
--- test/SemaObjC/access-property-getter.m
+++ test/SemaObjC/access-property-getter.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -fblocks -verify %s
 
 @protocol Protocol
 - (oneway void) method;
@@ -9,9 +9,27 @@
 }
 
 // rdar://19137815
+#pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-getter-return-value"
 
 void accessMethodViaPropertySyntaxWhenWarningIsIgnoredDoesNotTriggerWarning(id<Protocol> object) {
     object.method;
 }
 
+#pragma clang diagnostic pop
+
+@protocol ProtocolWithBlockProperty
+@property (readonly) void (^blockProperty)(void);
+@end
+
+id<ProtocolWithBlockProperty> protocolWithBlockPropertyConstructor(void);
+#define protocolWithBlockPropertyConstructorMacro protocolWithBlockPropertyConstructor
+
+void accessBlockPropertyDoesNotTriggerWarning(void) {
+    protocolWithBlockPropertyConstructorMacro().blockProperty;
+}
+
+void accessBlockPropertyInParenthesesTriggersWarning(void) {
+    (protocolWithBlockPropertyConstructorMacro()).blockProperty; // expected-warning {{property access result unused - getters should not be used for side effects}}
+}
+
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to