This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[objc] -Wselector when there are no @implementation:s

While working on PR18862, I found another bug in the -Wselector code: the warnings are only issued if there's an @implementation (class or category) somewhere in the file. selector-3.m shows this; a more realistic but less minimal example would be something like:

@interface Foo
-(void) foo;
void quux(void)

The reason is that the code in build_selector_translation_table that issues the warnings is guarded by:

if (warn_selector && objc_implementation_context)

build_selector_translation_table is called by finish_objc, and just before this call, finish_objc walks the list of implementations and sets objc_implementation_context to each one in turn. Thus, if there were any implementations, objc_implementation_context will be set to the last one in the list, and thus be non-NULL, when build_selector_translation_table is called; otherwise, it'll be NULL (earlier parts of finish_objc ensure this) and the warnings won't be issued.

I've attached a patch that fixes this by not checking objc_implementation_context before issuing the warnings. Bootstrapped (c,objc) on i686-pc-linux-gnu. 'make check-objc' has no new failures. I've verified that the new test fails on an unpatched compiler.

(The objc_implementation_context check has been there since the code was added by:
2002-08-08 Devang Patel <>
so perhaps Devang Patel can comment on why it's there, or if there's any reason to keep it. :)

- Alexander Malmberg

2005-01-27  Alexander Malmberg  <>

	* objc-act.c (build_selector_translation_table): Don't check
	objc_implementation_context before issuing -Wselector warnings.

2005-01-27  Alexander Malmberg  <>

* objc.dg/selector-3.m: New test.
Index: objc-act.c
RCS file: /cvsroot/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.263
diff -u -r1.263 objc-act.c
--- objc-act.c	25 Jan 2005 03:13:08 -0000	1.263
+++ objc-act.c	27 Jan 2005 00:06:15 -0000
@@ -2349,7 +2349,7 @@
       tree expr;
-      if (warn_selector && objc_implementation_context)
+      if (warn_selector)
         tree method_chain;
         bool found = false;
/* Test that we issue a warning even if there are no @implementation:s
   in the file.  */
/* { dg-options "-Wselector -fgnu-runtime" } */
/* { dg-do compile } */

void foo(void)
} /* { dg-warning "creating selector for nonexistent method .b1ar." } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]