From 7d08ba274959e110dfd4929cd2318a26083e6185 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 2 Mar 2016 14:12:17 +0000 Subject: [PATCH] [clang-tidy] Fix an assertion failure of "SLocEntry::getExpansion()" when IncludeInserter handles macro header file. Summary: Also Fixes PR24749. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17805 llvm-svn: 262484 --- .../clang-tidy/utils/IncludeInserter.cpp | 5 +++-- .../modernize-pass-by-value-marco-header.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/modernize-pass-by-value-marco-header.cpp diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp index 8f4bee6ad906..d128c691110a 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "IncludeInserter.h" +#include "clang/Lex/Token.h" namespace clang { namespace tidy { @@ -19,14 +20,14 @@ public: // Implements PPCallbacks::InclusionDerective(). Records the names and source // locations of the inclusions in the main source file being processed. void InclusionDirective(SourceLocation HashLocation, - const Token & /*include_token*/, + const Token & IncludeToken, StringRef FileNameRef, bool IsAngled, CharSourceRange FileNameRange, const FileEntry * /*IncludedFile*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, const Module * /*ImportedModule*/) override { Inserter->AddInclude(FileNameRef, IsAngled, HashLocation, - FileNameRange.getEnd()); + IncludeToken.getEndLoc()); } private: diff --git a/clang-tools-extra/test/clang-tidy/modernize-pass-by-value-marco-header.cpp b/clang-tools-extra/test/clang-tidy/modernize-pass-by-value-marco-header.cpp new file mode 100644 index 000000000000..660aaa432c13 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/modernize-pass-by-value-marco-header.cpp @@ -0,0 +1,16 @@ +// RUN: %check_clang_tidy %s modernize-pass-by-value %t -- -- -std=c++11 -isystem %S/Inputs/Headers + +// CHECK-FIXES: #include + +#define HEADER <./a.h> +#include HEADER + +struct A { +}; + +struct B { + B(const A &a) : a(a) {} +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass by value and use std::move [modernize-pass-by-value] +// CHECK-FIXES: B(A a) : a(std::move(a)) {} + A a; +}; -- GitLab