[clang-tools-extra] r341583 - Fix reported range of partial token replacement

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 6 13:16:34 PDT 2018


Author: steveire
Date: Thu Sep  6 13:16:34 2018
New Revision: 341583

URL: http://llvm.org/viewvc/llvm-project?rev=341583&view=rev
Log:
Fix reported range of partial token replacement

Summary: Fixes bug: 38678

Reviewers: klimek, rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D51192

Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=341583&r1=341582&r2=341583&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Sep  6 13:16:34 2018
@@ -122,10 +122,6 @@ public:
                   << Message.Message << Name;
       for (const auto &FileAndReplacements : Error.Fix) {
         for (const auto &Repl : FileAndReplacements.second) {
-          // Retrieve the source range for applicable fixes. Macro definitions
-          // on the command line have locations in a virtual buffer and don't
-          // have valid file paths and are therefore not applicable.
-          SourceRange Range;
           SourceLocation FixLoc;
           ++TotalFixes;
           bool CanBeApplied = false;
@@ -166,7 +162,11 @@ public:
             FixLoc = getLocation(FixAbsoluteFilePath, Repl.getOffset());
             SourceLocation FixEndLoc =
                 FixLoc.getLocWithOffset(Repl.getLength());
-            Range = SourceRange(FixLoc, FixEndLoc);
+            // Retrieve the source range for applicable fixes. Macro definitions
+            // on the command line have locations in a virtual buffer and don't
+            // have valid file paths and are therefore not applicable.
+            CharSourceRange Range =
+                CharSourceRange::getCharRange(SourceRange(FixLoc, FixEndLoc));
             Diag << FixItHint::CreateReplacement(Range,
                                                  Repl.getReplacementText());
           }




More information about the cfe-commits mailing list