[clang-tools-extra] r288145 - [include-fixer] Don't eat one token too many when replacing a block of includes.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 29 07:15:26 PST 2016
Author: d0k
Date: Tue Nov 29 09:15:26 2016
New Revision: 288145
URL: http://llvm.org/viewvc/llvm-project?rev=288145&view=rev
Log:
[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.
Modified:
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp
Modified: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp?rev=288145&r1=288144&r2=288145&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp Tue Nov 29 09:15:26 2016
@@ -136,10 +136,10 @@ static void addDiagnosticsForContext(Typ
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));
}
Modified: clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp?rev=288145&r1=288144&r2=288145&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp (original)
+++ clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp Tue Nov 29 09:15:26 2016
@@ -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
More information about the cfe-commits
mailing list