[cfe-users] got wrong parameter type using clang

Richard Smith via cfe-users cfe-users at lists.llvm.org
Wed Dec 11 10:13:14 PST 2019


On Tue, 10 Dec 2019, 22:45 henry ding via cfe-users, <
cfe-users at lists.llvm.org> wrote:

> simple test.cpp:
> void test(std::string xx,string bb,int aa){}
>
> clang usage:
> int getFuncInfo(Rewriter* TheRewrite,clang::ASTContext *Context, const
> FunctionDecl *func,FuncNode &node){
>     clang::LangOptions LangOpts;
>     LangOpts.CPlusPlus = true;
>     Policy.FullyQualifiedName = 1;
>    .............................................................
>   . ..........................................................
>    for(unsigned int i=0; i<func->getNumParams(); i++)
>            {
>                  string t =
> QualType::getAsString(func->getParamDecl(i)->getType().split(),Policy);
>                 string n =
>
> func->getParamDecl(i)->getName();//func->parameters()[i]->getQualifiedNameAsString()
>                  cout << t + "#" + n << endl;
>          }
> }
>
> But,i got:
> int#xx  //should string#xx
> int#bb //should string#bb
> int#aa
>
> Has anyone encountered this situation ?


The bug is probably somewhere else. Make sure the proper language options
are set up before parsing the source file, and that you're printing out any
diagnostics. My guess would be that the source is failing to compile (wrong
options, or can't find some standard header, or something), and the
diagnostics are being discarded, and clang is replacing the parameter type
with 'int' in error recovery.

_______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20191211/019948b8/attachment.html>


More information about the cfe-users mailing list