[cfe-dev] Showing ranges in a DiagnosticBuilder

Romanov Alexey via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 28 05:37:12 PST 2020


In a clang-tidy check I am writing, I want to show multiple ranges. And there is

inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                           ArrayRef<SourceRange> Ranges)

which seems to be exactly what I need. So I tried

SmallVector<SourceRange, 4> RangesToShow = ...;
auto Diag = diag(RangesToShow[0].getBegin(), AMessage) << RangesToShow;

and verified that in the test case RangesToShow.size() is 2, but instead of the desired (and expected)

<range1>  <range2>
^^^^^^^^  ^^^^^^^^

I see

<range1>  <range2>
^

I later found that getBegin() and getEnd() of the ranges returns the same location, but from my reading
of code this just means it's a single token, as expected. In case it was misinterpreted as an empty range, I also tried

auto Diag = diag(RangesToShow[0].getBegin(), AMessage);
auto Loc = RangesToShow[1].getBegin();
Diag.AddSourceRange(CharSourceRange::getCharRange(Loc, Loc.getLocationWithOffset(1));

with no success. What am I doing wrong?

(Also asked at https://stackoverflow.com/questions/59879527/showing-multiple-ranges-in-clang-diagnosticbuilder)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200128/2e130e63/attachment.html>


More information about the cfe-dev mailing list