Showing ranges in a DiagnosticBuilder

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 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)

^^^^^^^^ ^^^^^^^^

I see


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