[cfe-dev] Getting "wrong" ObjCMethodDecl-reference from ObjCMessageExpr

Hendrik vP variadic.template at googlemail.com
Sat May 5 10:17:20 PDT 2012


Hi,

while playing around with libClang and trying to extract some
statistics of objective-c-code, I encountered some strange behavior on
ObjCMessageExpressions.
ObjCMessageExpr-instances have a getMethodDecl-method, which I'm
expecting to return the _exact_ ObjCMethodDecl-instance if clang is
able to deduce it - or null, if clang has not the ability to do so.
Thus, sending a message to an id-variable should always return null.
Instead, I'm getting a ObjCMethodDecl-instance bound to the first
matching method-declaration within the code. Is this the expected
behavior?

Side information:
Using clang r156161
My code loads an ast-file and runs a RecursiveASTVisitor on it
The testcode for this case (gmail/Safari won't let me attach files, sorry)
// test: sending a message to a id-variable with two candidates for
objcmethoddecl
// expected: ObjCMessageExpr->getMethodDecl should return null, as
clang can't deduce the right ObjCMethodDecl for id-variables
// result: ObjCMessageExpr->getMethodDecl returns a methoddecl
belonging to Hotzi::murgel
@interface Hotzi
-(void)murgel;
@end

@implementation Hotzi
-(void)murgel {}
@end

@interface Mugi
-(void)bonk:(id)x;
-(void)murgel;
@end

@implementation Mugi

-(void)bonk:(id)x {
	[x murgel];
}

-(void)murgel {}

@end



More information about the cfe-dev mailing list