Clang question

Someone recently asked about a problem with a clang tutorial from:

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(

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:

should have been:

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

Am I missing something obvious here?

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);