Hi everybody,<br><br>I am new to clang and I am trying to learn it going through this tutorial: <a href="http://www.cs.rpi.edu/~laprej/clang.html">http://www.cs.rpi.edu/~laprej/clang.html</a><br>I have a very basic problem though.  After some work I ended up to this piece of code:<br>
<br>int main(int argc, char** argv)<br>{<br>    FileManager* fileManager = new FileManager();<br>    LangOptions* languageOptions = new LangOptions();<br>    languageOptions->BCPLComment=1;<br>    languageOptions->C99=1;<br>
    DiagnosticOptions* diagnosticOptions=new DiagnosticOptions();<br>    llvm::raw_os_ostream os(cout);<br>    TextDiagnosticPrinter* diagnosticClient=new TextDiagnosticPrinter(os,*diagnosticOptions,true);<br>    Diagnostic* diagnostic = new Diagnostic(diagnosticClient);<br>
    SourceManager* sourceManager= new SourceManager(*diagnostic);<br>    HeaderSearch* headerSearch = new HeaderSearch(*fileManager);<br>    TargetOptions targetOptions;<br>    targetOptions.Triple=LLVM_HOSTTRIPLE;<br>    TargetInfo *targetInfo = TargetInfo::CreateTargetInfo (*diagnostic, targetOptions);<br>
    Preprocessor* preprocessor = new Preprocessor(*diagnostic, *languageOptions, *targetInfo, *sourceManager, *headerSearch);<br>    const FileEntry* fileEntry=fileManager->getFile("test.c");<br>    sourceManager->createMainFileID(fileEntry);<br>
    preprocessor->EnterMainSourceFile();<br>    Token token;<br>    do<br>    {<br>        preprocessor->Lex(token);<br>        if(diagnostic->hasErrorOccurred())<br>        {<br>            break;<br>        }<br>
        preprocessor->DumpToken(token);<br>        std::cerr << std::endl;<br>    }<br>    while(token.isNot(tok::eof));<br>    diagnosticClient->EndSourceFile();<br>    return 0;<br>}<br><br>This works well with input files with not errors or no warnings.<br>
<br>Then I give as input this very minimalistic file (test.c):<br><br>int main() {<br>  /* Nested /* comments */ <br>}<br><br>The parsing of this code should produce a warning for the presence of the nested comment, but instead I get this output:<br>
<br>int 'int'<br>identifier 'main'<br>l_paren '('<br>r_paren ')'<br>l_brace '{'<br>clangExample: TextDiagnosticPrinter.cpp:298: void clang::TextDiagnosticPrinter::EmitCaretDiagnostic(clang::SourceLocation, clang::CharSourceRange*, unsigned int, const clang::SourceManager&, const clang::FixItHint*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int): Assertion `LangOpts && "Unexpected diagnostic outside source file processing"' failed.<br>
<br>The problem is that the preprocessor tries to output the diagnostic message outside the right context. I also tried to call the diagnosticClient->BeginSourceFile function before the parsing of the file but no warning is displayed either, the parsing is stopped with no messages at all.<br>
<br>I also tried the CompilerInstance/CompilerInvocation approach with the same result.<br><br>How can I fix this issue? Where am I wrong ?<br><br>Any help is greatly appreciated.<br><br>Thank you in advance<br><br>Alberto<br>