diff --git a/clang/Rewrite/Rewriter.cpp b/clang/Rewrite/Rewriter.cpp index 87a5deaf1a98..514b82235a47 100644 --- a/clang/Rewrite/Rewriter.cpp +++ b/clang/Rewrite/Rewriter.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/Rewrite/Rewriter.h" +#include "clang/Lex/Lexer.h" #include "clang/Basic/SourceManager.h" using namespace clang; @@ -156,6 +157,10 @@ int Rewriter::getRangeSize(SourceRange Range) const { if (StartFileID != EndFileID) return -1; + // Adjust the end offset to the end of the last token, instead of being the + // start of the last token. + EndOff += Lexer::MeasureTokenLength(Range.getEnd(), *SourceMgr); + return EndOff-StartOff; }