"Unexpected diagnostic outside source file processing" ?

Hello all.

I'm just getting started with Clang, with the aim of using it to do
static analysis on some C99 code. I've got as far as successfully
parsing to AST, but I'm getting the following failure when my test
file "mytestfile.c" contains any sort of syntax error:

    Assertion failed: (LangOpts && "Unexpected diagnostic outside
source file processing"),
    function EmitCaretDiagnostic, file TextDiagnosticPrinter.cpp, line 293.

Clearly I've failed to initialize the language options correctly
somewhere, but I can't figure out where. Can anyone give me any

Here's the code I'm using, minus the necessary #includes..

using namespace clang;

int main(int argc, const char** argv) {
    DiagnosticOptions DiagOpts;
    llvm::IntrusiveRefCntPtr<Diagnostic> Diags =
        CompilerInstance::createDiagnostics(DiagOpts, 0, NULL);

    CompilerInvocation *cv = new CompilerInvocation;
    CompilerInvocation::CreateFromArgs(*cv, argv+1, argv+argc, *Diags);

    CompilerInstance ci;





    ASTConsumer consumer;


    return 0;

The file "mytestfile.c" just contains:

int main(void) {
  syntax error;

Any hints appreciated.