This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [objc] -Wselector when there are no @implementation:s
- From: Devang Patel <dpatel at apple dot com>
- To: Alexander Malmberg <alexander at malmberg dot org>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 27 Jan 2005 10:55:09 -0800
- Subject: Re: [objc] -Wselector when there are no @implementation:s
- References: <41F83E75.6000607@malmberg.org>
On Jan 26, 2005, at 5:05 PM, Alexander Malmberg wrote:
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;
@end
void quux(void)
{
@selector(f00);
}
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 <dpatel@apple.com>
so perhaps Devang Patel can comment on why it's there, or if there's
any reason to keep it. :)
Original intention was to warn inside @implementation only. It is up to
ObjC maintainers to decide whether to extend its scope or not.
-
Devang