[include-fixer] Don't eat one token too many when replacing a block of includes.

SourceRanges are inclusive token ranges, this was trying to form an
exclusive char range.

llvm-svn: 288145
This commit is contained in:
Benjamin Kramer 2016-11-29 15:15:26 +00:00
parent 11c5e07925
commit b2a346d5e4
2 changed files with 4 additions and 3 deletions

View File

@ -136,10 +136,10 @@ static void addDiagnosticsForContext(TypoCorrection &Correction,
const tooling::Replacement &Placed = *Reps->begin();
auto Begin = StartOfFile.getLocWithOffset(Placed.getOffset());
auto End = Begin.getLocWithOffset(Placed.getLength());
auto End = Begin.getLocWithOffset(std::max(0, (int)Placed.getLength() - 1));
PartialDiagnostic PD(DiagID, Ctx.getDiagAllocator());
PD << Context.getHeaderInfos().front().Header
<< FixItHint::CreateReplacement(SourceRange(Begin, End),
<< FixItHint::CreateReplacement(CharSourceRange::getCharRange(Begin, End),
Placed.getReplacementText());
Correction.addExtraDiagnostic(std::move(PD));
}

View File

@ -8,7 +8,8 @@ unknown u;
// CHECK: FIX-IT: Replace [3:1 - 3:4] with "foo"
// CHECK: yamldb_plugin.cpp:3:1: note: Add '#include "foo.h"' to provide the missing declaration [clang-include-fixer]
// CHECK: Number FIX-ITs = 1
// CHECK: FIX-IT: Replace [3:1 - 3:4] with "#include "foo.h"
// CHECK: FIX-IT: Insert "#include "foo.h"
// CHECK: " at 3:1
// CHECK: yamldb_plugin.cpp:4:1:
// CHECK: error: unknown type name 'unknown'
// CHECK: Number FIX-ITs = 0