using this dummy source file<br><br>struct AA {<br> int a, b, c;<br> void ff(int z){ }<br>};<br>void funcAZ() {}<br>int main(){<br> struct AA aa;<br> int a=1;<br>}<br><br>I ran the code at the end of this email. there are no cmd line arguments and the file is a.cpp.<br>
<br>When it runs my ASTConsumer i get the assert error<br><br>Unexpected diagnostic outside source file processing<br><br>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.<br>
How do i tell it to compile in C++ mode?<br><br><br> CompilerInstance compiler;<br> <br> compiler.createDiagnostics(argc, argv);<br> CompilerInvocation::CreateFromArgs( compiler.getInvocation(),<br> argv + 1, argv + argc, compiler.getDiagnostics() );<br>
<br> compiler.setTarget( TargetInfo::CreateTargetInfo(<br> compiler.getDiagnostics(), compiler.getTargetOpts() ) );<br> <br> compiler.createFileManager();<br> compiler.createSourceManager(compiler.getFileManager());<br>
compiler.createPreprocessor();<br> compiler.createASTContext();<br> compiler.setASTConsumer( new PrintFunctionsConsumer);<br> <br> compiler.createSema(false, NULL);<br> <br> <br> compiler.InitializeSourceManager( main_input_file );<br>
ParseAST( compiler.getPreprocessor(), &compiler.getASTConsumer(), compiler.getASTContext() );<br><div></div>