[cfe-dev] Clang question

Craig Topper craig.topper at gmail.com
Sun Aug 18 09:58:18 PDT 2013


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<DiagnosticsEngine>
  createDiagnostics(DiagnosticOptions *Opts,
                    DiagnosticConsumer *Client = 0,
                    bool ShouldOwnClient = true,
                    const CodeGenOptions *CodeGenOpts = 0);


On Sun, Aug 18, 2013 at 5:42 AM, Robert Ankeney <rrankene at gmail.com> wrote:

> 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
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>


-- 
~Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130818/f81ff607/attachment.html>


More information about the cfe-dev mailing list