[cfe-dev] Extracting variable name from VarDecl* Clang
Miklos Vajna via cfe-dev
cfe-dev at lists.llvm.org
Sat Jun 4 05:36:50 PDT 2016
On Sat, Jun 04, 2016 at 05:32:37PM +0530, Dhriti Khanna via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> This code:
>
> if (IfStmt* ifS = dyn_cast<IfStmt>(st)) {
> errs() << "Found an IF statement ";
> VarDecl* var = ifS->getConditionVariable();
> errs() << var->getNameAsString();
> }
>
> produces cannot initialize object parameter of type 'const
> clang::NamedDecl' with an expression of type 'clang::VarDecl' error on errs()
> << var->getNameAsString(); line and the program crashes with a seg fault. I
> can't find what's wrong with this? Please help.
Please post some sample source code (from which the AST is generated),
without that it's quite hard to help. But in general I guess you can't
assume that you can get a single variable out of an if statement, if you
have "if (Foo && Bar)", which one would be returned by the API?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160604/eeeafe3a/attachment.sig>
More information about the cfe-dev
mailing list