Showing ranges in a DiagnosticBuilder

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Showing ranges in a DiagnosticBuilder

Hans Wennborg via cfe-dev

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


cfe-dev mailing list
[hidden email]