diff mbox

ObjC/ObjC++: print warning when a class or protocol attribute is ignored

Message ID 84638118-0DC8-4C08-B017-808962994FC9@meta-innovation.com
State New
Headers show

Commit Message

Nicola Pero Dec. 29, 2010, 11:06 p.m. UTC
This patch adds the missing warning when a class or protocol attribute  
is ignored.  Testcases included.

Ok to commit ?

Thanks

++ (id) new;
+@end
Index: testsuite/obj-c++.dg/attributes/proto-attribute-4.mm
===================================================================
--- testsuite/obj-c++.dg/attributes/proto-attribute-4.mm         
(revision 0)
+++ testsuite/obj-c++.dg/attributes/proto-attribute-4.mm         
(revision 0)
@@ -0,0 +1,31 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>,  
December 2010.  */
+/* { dg-do compile } */
+
+/* Test that you get a warning when an unknown protocol attribute is  
ignored.  */
+
+#include <objc/objc.h>
+
+__attribute__ ((unknown_attribute))
+@protocol MyProtocol /* { dg-warning "ignored" } */
+- (id) new;
+@end
+
+__attribute__ ((unknown_attribute))
+@protocol MyProtocol2; /* { dg-warning "ignored" } */
+
+/* Use the protocols to double-check that no more warnings are
+   generated.  */
+
+@interface MyClass <MyProtocol>
+@end
+
+int test (id <MyProtocol2> x)
+{
+  if (@protocol (MyProtocol) == @protocol (MyProtocol2))
+    return 1;
+
+  if (x)
+    return 2;
+
+  return 3;
+}
ndex: testsuite/obj-c++.dg/attributes/class-attribute-3.mm
===================================================================
--- testsuite/obj-c++.dg/attributes/class-attribute-3.mm         
(revision 0)
+++ testsuite/obj-c++.dg/attributes/class-attribute-3.mm         
(revision 0)
@@ -0,0 +1,14 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>,  
December 2010.  */
+/* { dg-do compile } */
+
+/* Test that you get a warning when an unknown class attribute is  
ignored.  */
+
+#include <objc/objc.h>
+
+__attribute__ ((unknown_attribute))
+@interface MyClass /* { dg-warning "ignored" } */
+{
+  Class isa;
+}
++ (id) new;
+@end

Comments

Mike Stump Dec. 29, 2010, 11:16 p.m. UTC | #1
On Dec 29, 2010, at 3:06 PM, Nicola Pero wrote:
> This patch adds the missing warning when a class or protocol attribute is ignored.  Testcases included.
> 
> Ok to commit ?

Ok.
diff mbox

Patch

Index: objc/objc-act.c
===================================================================
--- objc/objc-act.c     (revision 168326)
+++ objc/objc-act.c     (working copy)
@@ -9714,6 +9714,8 @@  start_class (enum tree_code code, tree c

               if (is_attribute_p  ("deprecated", name))
                 TREE_DEPRECATED (klass) = 1;
+             else
+               warning (OPT_Wattributes, "%qE attribute directive  
ignored", name);
             }
           TYPE_ATTRIBUTES (klass) = attributes;
         }
@@ -10916,6 +10918,8 @@  objc_declare_protocols (tree names, tree

           if (is_attribute_p  ("deprecated", name))
             deprecated = true;
+         else
+           warning (OPT_Wattributes, "%qE attribute directive  
ignored", name);
         }
      }

@@ -10969,6 +10973,8 @@  start_protocol (enum tree_code code, tre

           if (is_attribute_p  ("deprecated", name))
             deprecated = true;
+         else
+           warning (OPT_Wattributes, "%qE attribute directive  
ignored", name);
         }
      }

Index: objc/ChangeLog
===================================================================
--- objc/ChangeLog      (revision 168326)
+++ objc/ChangeLog      (working copy)
@@ -1,3 +1,11 @@ 
+2010-12-30  Nicola Pero  <nicola@nicola.brainstorm.co.uk>
+
+       * objc-act.c (start_class): Warn when a class attribute is
+       ignored.
+       (objc_declare_protocols): Warn when a protocol attribute in a
+       protocol forward-declaration is ignored.
+       (start_protocol): Warn when a protocol attribute is ignored.
+
  2010-12-29  Nicola Pero  <nicola.pero@meta-innovation.com>

         PR objc/47118
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (revision 168326)
+++ testsuite/ChangeLog (working copy)
@@ -1,3 +1,10 @@ 
+2010-12-30  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc.dg/attributes/class-attribute-3.m: New.
+       * objc.dg/attributes/proto-attribute-4.m: New.
+       * obj-c++.dg/attributes/class-attribute-3.mm: New.
+       * obj-c++.dg/attributes/proto-attribute-4.mm: New.
+
  2010-12-29  Nicola Pero  <nicola.pero@meta-innovation.com>

         PR objc/47118
Index: testsuite/objc.dg/attributes/proto-attribute-4.m
===================================================================
--- testsuite/objc.dg/attributes/proto-attribute-4.m    (revision 0)
+++ testsuite/objc.dg/attributes/proto-attribute-4.m    (revision 0)
@@ -0,0 +1,31 @@ 
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>,  
December 2010.  */
+/* { dg-do compile } */
+
+/* Test that you get a warning when an unknown protocol attribute is  
ignored.  */
+
+#include <objc/objc.h>
+
+__attribute__ ((unknown_attribute))
+@protocol MyProtocol
+- (id) new; /* { dg-warning "ignored" } */
+@end
+
+__attribute__ ((unknown_attribute))
+@protocol MyProtocol2; /* { dg-warning "ignored" } */
+
+/* Use the protocols to double-check that no more warnings are
+   generated.  */
+
+@interface MyClass <MyProtocol>
+@end
+
+int test (id <MyProtocol2> x)
+{
+  if (@protocol (MyProtocol) == @protocol (MyProtocol2))
+    return 1;
+
+  if (x)
+    return 2;
+
+  return 3;
+}
Index: testsuite/objc.dg/attributes/class-attribute-3.m
===================================================================
--- testsuite/objc.dg/attributes/class-attribute-3.m    (revision 0)
+++ testsuite/objc.dg/attributes/class-attribute-3.m    (revision 0)
@@ -0,0 +1,14 @@ 
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>,  
December 2010.  */
+/* { dg-do compile } */
+
+/* Test that you get a warning when an unknown class attribute is  
ignored.  */
+
+#include <objc/objc.h>
+
+__attribute__ ((unknown_attribute))
+@interface MyClass
+{ /* { dg-warning "ignored" } */
+  Class isa;
+}