[cfe-dev] CompilerInstance as CPP compiler?

Hendrik vP variadic.template at googlemail.com
Tue Jun 28 08:06:31 PDT 2011


Either your adding the "-x c++"-option to your compilercreateion, or, by
code, you can take the language-options of the compiler and set the
appropriate flags by yourself
LangOptions lopts= compiler.getLangOptions(); (
http://clang.llvm.org/doxygen/classclang_1_1LangOptions.html)

2011/6/22 Adam Smalin <acidzombie24 at gmail.com>

> using this dummy source file
>
> struct AA {
>     int a, b, c;
>     void ff(int z){ }
> };
> void funcAZ() {}
> int main(){
>     struct AA aa;
>     int a=1;
> }
>
> I ran the code at the end of this email. there are no cmd line arguments
> and the file is a.cpp.
>
> When it runs my ASTConsumer i get the assert error
>
> Unexpected diagnostic outside source file processing
>
> however if i remove the ff function in AA, it runs fine. I assume the
> problem is the compiler is running in c mode and i am using c++ source.
> How do i tell it to compile in C++ mode?
>
>
>     CompilerInstance compiler;
>
>     compiler.createDiagnostics(argc, argv);
>     CompilerInvocation::CreateFromArgs( compiler.getInvocation(),
>     argv + 1, argv + argc, compiler.getDiagnostics() );
>
>     compiler.setTarget( TargetInfo::CreateTargetInfo(
>     compiler.getDiagnostics(), compiler.getTargetOpts() ) );
>
>     compiler.createFileManager();
>     compiler.createSourceManager(compiler.getFileManager());
>     compiler.createPreprocessor();
>     compiler.createASTContext();
>     compiler.setASTConsumer( new PrintFunctionsConsumer);
>
>     compiler.createSema(false, NULL);
>
>
>     compiler.InitializeSourceManager( main_input_file );
>     ParseAST( compiler.getPreprocessor(), &compiler.getASTConsumer(),
> compiler.getASTContext() );
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110628/d12b98a4/attachment.html>


More information about the cfe-dev mailing list