Clang question

Someone recently asked about a problem with a clang tutorial from:
https://github.com/loarabia/Clang-tutorial

There was a piece of code common to many of the tutorials (since fixed in the latest version):

CompilerInstance ci;
DiagnosticOptions diagnosticOptions;
TextDiagnosticPrinter *pTextDiagnosticPrinter =
new TextDiagnosticPrinter(
llvm::outs(),
&diagnosticOptions,
true);
ci.createDiagnostics(pTextDiagnosticPrinter);

that was causing a runtime error due to an unfreed pointer (which was true). But looking at the code and the documentation for CompilerInstance, it seems the line:
ci.createDiagnostics(pTextDiagnosticPrinter);

should have been:
ci.createDiagnostics(&diagnosticOptions);

and the first call should have been flagged as an error by clang.

Am I missing something obvious here?

Thanks,
Robert Ankeney

There are two different createDiagnostics methods with different signatures. TextDiagnosticPrinter inherits from DiagnosticConsumer so pTextDiagnosticPrinter would have called the first signature. &DiagnosticOptions calls the second signature.

void createDiagnostics(DiagnosticConsumer *Client = 0,
bool ShouldOwnClient = true);

static IntrusiveRefCntPtr
createDiagnostics(DiagnosticOptions *Opts,
DiagnosticConsumer *Client = 0,
bool ShouldOwnClient = true,
const CodeGenOptions *CodeGenOpts = 0);