[PATCH] D12048: Verify no result unused warning on macro expansion

Brian Gesiak via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 19:46:39 PDT 2015


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
+
+ at protocol ProtocolWithBlockProperty
+ at property (readonly) void (^blockProperty)(void);
+ at 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}}
+}
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12048.32214.patch
Type: text/x-patch
Size: 1249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150815/3b1c8141/attachment-0001.bin>


More information about the cfe-commits mailing list