[cfe-dev] Question about InsertTextBefore() a function decl whose return type is typedef'd.

Gabor Kozar via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 14 16:06:37 PDT 2015

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.

Best regards,

Gábor 'ShdNx' Kozár http://gaborkozar.me

On Tue, Sep 8, 2015, at 06:54, Yogesh Chobe via cfe-dev wrote:
> 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
> _________________________________________________
> cfe-dev mailing list cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150915/259d832a/attachment.html>

More information about the cfe-dev mailing list