Question about InsertTextBefore() a function decl whose return type is typedef'd.

Hi All,

In the ASTVisitor, when I hit VisitDecl(Decl* d) for a function of interest, I am inserting some code above that function using TheRewriter.InsertTextBefore(d->getSourceRange().getBegin(), someString);

This has been working out great for a while, but I hit upon some user code which has a typedef’d return type. In this case, I don’t see anything being inserted. My hypothesis is that the typedef is expanded at the point where I am inserting into the AST and when I write the user code back to disk, the expanded type and my changes are all replaced by the typedef’d symbol.

I tried to do a getLocWithOffset(-1) type of thing to the getBegin() but that did not help. Is there a way to say insertAfterPreviousLine() kind of a thing? I am using the 3.5 release version and I could not find an easy way to get a handle to the line above the function declaration.

Thanks,
Yogesh

This sounds like a bug in clang.

typedefs are not expanded in the same way that macros are, and should not cause the same misery on SourceLocations as they do. Verify that the source range you’re getting is valid.