<div dir="ltr"><div dir="ltr">Hi Andrzej,<div><br></div><div>thanks for the reply. My code is basically identical to the mccabe example:</div><div><br></div><div>454             const clang::BinaryOperator *binOp = parents[0].get<clang::BinaryOperator>();<br>455             if (!binOp || binOp->getOpcodeStr() != std::string("="))  // TODO check for isAssignmentOp<br>456             {<br>457                 auto& Diagnostics = mContext->getDiagnostics();<br>458                 const auto ID = Diagnostics.getCustomDiagID(clang::DiagnosticsEngine::Error,<br>459                                                             "Return value from '%0' is not assigned");<br>460                 auto Builder = Diagnostics.Report(fnDecl->getLocation(), ID);<br>461                 Builder.AddString(fnDecl->getNameAsString());<br>462<br>463                 cout << "ERROR: Return val from API call not assigned '" << Diagnostics.getClient() << " " << fnDecl->getNameAsString()<br>464                 return true;<br>465             }<br></div><div><br></div><div>I know that my DiagnosticsEngine does have a DiagnosticConsumer as Diagnostics.getClient() returns non-null.</div><div><br></div><div>My understanding is that when the Build object is destroyed after the return that the diagnostic should be emitted.</div><div><br></div><div><div>I will have a look at those samples.</div></div><div><br></div><div>Thanks,</div><div>Billy.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 9 Oct 2020 at 20:18, Andrzej Warzynski <<a href="mailto:andrzej.warzynski@arm.com">andrzej.warzynski@arm.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Billy,<br>
<br>
It's a bit tricky to help without seeing the code :) Are you using any <br>
specific/custom diagnostic consumer? Is your properly DiagnosticBuilder <br>
destroyed? AFAIK, that's when the message is printed.<br>
<br>
Here's a bit more up-to-date example:<br>
* <br>
<a href="https://github.com/banach-space/clang-tutor/blob/master/lib/CodeStyleChecker.cpp#L97-L102" rel="noreferrer" target="_blank">https://github.com/banach-space/clang-tutor/blob/master/lib/CodeStyleChecker.cpp#L97-L102</a><br>
And a test that verifies that the diagnostic is indeed printed:<br>
* <br>
<a href="https://github.com/banach-space/clang-tutor/blob/master/test/CodeStyleCheckerMacro.cpp" rel="noreferrer" target="_blank">https://github.com/banach-space/clang-tutor/blob/master/test/CodeStyleCheckerMacro.cpp</a><br>
<br>
Happy to help if that example doesn't work for you! Hopefully it will <br>
help debugging your own code :)<br>
<br>
-Andrzej<br>
<br>
On 09/10/2020 16:26, Billy O'Mahony via cfe-dev wrote:<br>
> Hi,<br>
> <br>
> hopefully a straightforward issue.<br>
> <br>
> I have written a standalone cfe tool to catch some project-specific bugs <br>
> in a code base.<br>
> <br>
> I am now replacing my cout << "ERROR..." messages with <br>
> clang::Diagnostics by following this example:<br>
> <br>
> <a href="https://github.com/peter-can-talk/cppnow-2017/blob/master/code/mccabe/mccabe.cpp#L46-L54" rel="noreferrer" target="_blank">https://github.com/peter-can-talk/cppnow-2017/blob/master/code/mccabe/mccabe.cpp#L46-L54</a><br>
> <br>
> However I don't see anything being printed when I run it (except my own <br>
> cout << "error.." messages)..<br>
> <br>
> I've seen the mcabbe example generate diagnostics on a <br>
> youtube presentation and both it and my app use <br>
> clang::Tool.  mccabbe uses ast_matcher::MatchFinder whereas I use <br>
> several classes derived from RecursiveASTVisitor. Presumably MatchFinder <br>
> sets up a DiagnosticsConsumer that finally emits the diagnostics??<br>
> <br>
> But I couldn't really find out how to set up a DiagnosticsConsumer - if <br>
> that is indeed what I need to do.<br>
> <br>
> Thanks,<br>
> Billy.<br>
> <br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
> <br>
</blockquote></div>