objc-act.c (build_selector_translation_table): Issue warning...
authorDevang Patel <dpatel@apple.com>
Thu, 8 Aug 2002 23:14:19 +0000 (16:14 -0700)
committerDevang Patel <dpatel@gcc.gnu.org>
Thu, 8 Aug 2002 23:14:19 +0000 (16:14 -0700)
        * objc/objc-act.c (build_selector_translation_table): Issue
warning, when  -Wselector is used,if method for which selector
is being created does not exist.

Testsuite:
*objc.dg/selector-1.m: New test

From-SVN: r56142

gcc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/selector-1.m [new file with mode: 0644]

index fa7430eeedf604ead2969e6f6f71aabdfaa431cd..7c22cb673c19587802f2d82b57c6deb07ec1311d 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-08  Devang Patel  <dpatel@apple.com>
+       * objc/objc-act.c (build_selector_translation_table): Issue warning, 
+       when  -Wselector is used,if method for which selector is being 
+       created does not exist.
+       
 2002-08-08  Stephen Clarke <stephen.clarke@superh.com>
 
        * config/sh/sh.c (prepare_move_operands): Only call
index 7ebb9f2a20252a02673ff39b603599eec845cb97..c16e57c79339de837fe806e6ab227ecc55c7fc49 100644 (file)
@@ -1886,6 +1886,32 @@ build_selector_translation_table ()
     {
       tree expr;
 
+      if (warn_selector && objc_implementation_context)
+      {
+        tree method_chain;
+        bool found = false;
+        for (method_chain = meth_var_names_chain;
+             method_chain;
+             method_chain = TREE_CHAIN (method_chain))
+          {
+            if (TREE_VALUE (method_chain) == TREE_VALUE (chain))
+              {
+                found = true;
+                break;
+              }
+          }
+        if (!found)
+          {
+            /* Adjust line number for warning message.  */
+            int save_lineno = lineno;
+            if (flag_next_runtime && TREE_PURPOSE (chain))
+              lineno = DECL_SOURCE_LINE (TREE_PURPOSE (chain));
+            warning ("creating selector for non existant method %s",
+                     IDENTIFIER_POINTER (TREE_VALUE (chain)));
+            lineno = save_lineno;
+          }
+      }
+
       expr = build_selector (TREE_VALUE (chain));
 
       if (flag_next_runtime)
index 0f7dfe570cf87399f7061dbf9080e76c3412851a..07c3a50b94f35d0d9ab772a7613f3372e2c9fcfd 100644 (file)
@@ -1,3 +1,6 @@
+2002-08-08  Devang Patel  <dpatel@apple.com>
+       *objc.dg/selector-1.m : New test
+       
 2002-08-08  Nathan Sidwell  <nathan@codesourcery.com>
 
        * g++.dg/abi/bitfield4.c: New test.
diff --git a/gcc/testsuite/objc.dg/selector-1.m b/gcc/testsuite/objc.dg/selector-1.m
new file mode 100644 (file)
index 0000000..b23cc90
--- /dev/null
@@ -0,0 +1,26 @@
+/* Test warning for non existing selectors.  */
+/* Contributed by Devang Patel <dpatel@apple.com>.  */
+/* { dg-options "-Wselector -fnext-runtime" } */
+/* { dg-do compile } */
+
+typedef struct objc_object { struct objc_class *class_pointer; } *id;
+typedef struct objc_selector    *SEL;
+
+@interface Foo
+- (void) foo;
+- (void) bar;
+@end
+
+@implementation Foo
+- (void) bar
+{
+}
+
+- (void) foo
+{
+  SEL a,b,c;
+  a = @selector(b1ar); /* { dg-warning "creating selector for non existant method b1ar" } */
+  b = @selector(bar);
+}
+@end
+