<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 04/02/16 18:28, Tim Halloran wrote:<br>
    <blockquote
cite="mid:CAFdkBy4UY9dHsn-_DMec-Dfo4tZ8icdz7iX4=zem=+7J4fA1rw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">On Thu, Feb 4, 2016 at 11:37 AM,
            Piotr Dziwinski <span dir="ltr"><<a
                moz-do-not-send="true" href="mailto:piotrdz@gmail.com"
                target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:piotrdz@gmail.com">piotrdz@gmail.com</a></a>></span> wrote:<br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
              <div text="#000000" bgcolor="#FFFFFF"><span>Yes, you can
                  add many fix it hints for a given diagnostic. For
                  example:<br>
                  <br>
                    auto Diagnostic = </span><span>diag(Loc, "</span>diagnostic")<span>;<br>
                    Diagnostic.</span><span>AddFixItHint(<span>FixItHint::CreateInsertion</span>(/*...*/<span></span>));<br>
                </span><span><span>  Diagnostic.</span><span>AddFixItHint(<span>FixItHint::CreateRemoval</span>(<span></span>/*...*/));<br>
                    <br>
                    This can also be achieved through overloaded
                    operator<< which is just a wrapper for the
                    same function calls.<br>
                  </span></span></div>
            </blockquote>
            <div><br>
            </div>
            <div>This works during the same call to "check"  However if
              I stash the pointer to the "Diagnostic" variable (e.g., in
              a map) and lookup and use the reference later I'm getting
              a core dump. I'm guessing that is because the object
              created by "diag()" call is not intended to be stashed.</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    As far as I know, diagnostics are meant to be generated on the fly
    and pushed out to the diagnostics handler as soon as possible.<br>
    I don't know if it's possible to store any long-lived reference to
    them.<br>
    <br>
    <blockquote
cite="mid:CAFdkBy4UY9dHsn-_DMec-Dfo4tZ8icdz7iX4=zem=+7J4fA1rw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>Is there a way to get a clang::DiagnosticBuilder object
              that can be safely stashed?</div>
            <div><br>
            </div>
            <div>What I am doing is first removing somthing like</div>
            <div><br>
            </div>
            <div>using namespace sl;</div>
            <div><br>
            </div>
            <div>from the code</div>
            <div><br>
            </div>
            <div>then adding qualifiers for each use, e.g., "foo"
              becomes "sl::foo"</div>
            <div><br>
            </div>
            <div>so the "add qualifier" part gets identified in later
              calls to "check"</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    As a workaround, you can try a different approach - store additional
    state in your check class and update it on each check() call.<br>
    Then, once you have complete context information about the code you
    want to change, create a full diagnostic with all needed data.<br>
    <br>
    This is actually what I do in some of my checks, especially the
    localizing variables check that I'm still working on:<br>
<a class="moz-txt-link-freetext" href="https://github.com/piotrdz/clang-tools-extra/blob/master/clang-tidy/readability/LocalizingVariablesCheck.cpp">https://github.com/piotrdz/clang-tools-extra/blob/master/clang-tidy/readability/LocalizingVariablesCheck.cpp</a><br>
    <br>
    Best regards,<br>
    Piotr Dziwinski<br>
  </body>
</html>