summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Grasman <kim.grasman@gmail.com>2016-03-20 15:49:33 +0100
committerKim Grasman <kim.grasman@gmail.com>2016-03-20 15:49:33 +0100
commit0f76ccbf0a487cd00ae216e21cad2933474f12bd (patch)
tree18554772a9f88dd1a0df6c8508e240bb9a4849f7
parent178b04f01403ff8cf26fc359640e25ae202c7c4a (diff)
Fix IsInScratchSpace so it actually works.
Scratch space locations look like "<scratch space>:line:col", but we compared directly against "<scratch space>", which would always fail. Move macro-arg-concatenation test from badinc to macro_location to make it easier to detect failures in the future.
-rw-r--r--iwyu_location_util.cc2
-rw-r--r--tests/cxx/badinc.cc7
-rw-r--r--tests/cxx/macro_location-d3.h1
-rw-r--r--tests/cxx/macro_location-i4.h12
-rw-r--r--tests/cxx/macro_location.h12
5 files changed, 26 insertions, 8 deletions
diff --git a/iwyu_location_util.cc b/iwyu_location_util.cc
index 7a5fcc7..8e4c4e7 100644
--- a/iwyu_location_util.cc
+++ b/iwyu_location_util.cc
@@ -168,7 +168,7 @@ SourceLocation GetLocation(const clang::TemplateArgumentLoc* argloc) {
}
bool IsInScratchSpace(SourceLocation loc) {
- return PrintableLoc(GetSpellingLoc(loc)) == "<scratch space>";
+ return StartsWith(PrintableLoc(GetSpellingLoc(loc)), "<scratch space>");
}
} // namespace include_what_you_use
diff --git a/tests/cxx/badinc.cc b/tests/cxx/badinc.cc
index de3fb18..f63838c 100644
--- a/tests/cxx/badinc.cc
+++ b/tests/cxx/badinc.cc
@@ -73,8 +73,6 @@
#include <algorithm> // try #including the same file twice
#include <algorithm> // ...and then 3 times
-#define CONCAT(a, b) a##b
-
// This should given an IWYU error even though MACRO_CALLING_I1_MACRO
// is never actually called.
// IWYU: MACRO_CALLING_I6_FUNCTION is...*badinc-i1.h
@@ -1448,11 +1446,6 @@ int main() {
MACRO_CALLING_I6_FUNCTION;
// IWYU: kI1ConstInt is...*badinc-i1.h
(void)(kI1ConstInt);
- // IWYU: kI1ConstInt is...*badinc-i1.h
- (void)(CONCAT(kI1C, onstInt));
- // IWYU: I1_Class needs a declaration
- CONCAT(I1_, Class) *i1_concat_class_ptr; // also test something fwd-decl
- (void)(i1_concat_class_ptr);
Cc_string().length();
diff --git a/tests/cxx/macro_location-d3.h b/tests/cxx/macro_location-d3.h
index 651ecc7..89a2693 100644
--- a/tests/cxx/macro_location-d3.h
+++ b/tests/cxx/macro_location-d3.h
@@ -8,3 +8,4 @@
//===----------------------------------------------------------------------===//
#include "tests/cxx/macro_location-i3.h"
+#include "tests/cxx/macro_location-i4.h"
diff --git a/tests/cxx/macro_location-i4.h b/tests/cxx/macro_location-i4.h
new file mode 100644
index 0000000..f61332e
--- /dev/null
+++ b/tests/cxx/macro_location-i4.h
@@ -0,0 +1,12 @@
+//===--- macro_location-i4.h - test input file for iwyu -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+class ConcatClass {};
+
+class ConcatFwdDeclClass {};
diff --git a/tests/cxx/macro_location.h b/tests/cxx/macro_location.h
index 007b2f6..0e49247 100644
--- a/tests/cxx/macro_location.h
+++ b/tests/cxx/macro_location.h
@@ -27,10 +27,21 @@ CREATE_VAR(HClass);
// forward-declared by DECLARE_INDIRECT's file.
DECLARE_INDIRECT(global_indirect);
+// Macro-concatenated locations end up in <scratch space>, check that they're
+// properly attributed to expansion.
+#define CONCAT(a, b) a##b
+
+// IWYU: ConcatFwdDeclClass needs a declaration
+CONCAT(Concat, FwdDeclClass) *global_concat_ptr;
+
+// IWYU: ConcatClass is...*macro_location-i4.h
+CONCAT(Concat, Class) global_concat;
+
/**** IWYU_SUMMARY
tests/cxx/macro_location.h should add these lines:
#include "tests/cxx/macro_location-i3.h"
+#include "tests/cxx/macro_location-i4.h"
tests/cxx/macro_location.h should remove these lines:
- #include "tests/cxx/macro_location-d3.h" // lines XX-XX
@@ -40,6 +51,7 @@ The full include-list for tests/cxx/macro_location.h:
#include "tests/cxx/indirect.h" // for IndirectClass
#include "tests/cxx/macro_location-d2.h" // for ARRAYSIZE, CREATE_VAR, DECLARE_INDIRECT, NEW_CLASS, USE_CLASS
#include "tests/cxx/macro_location-i3.h" // for Foo
+#include "tests/cxx/macro_location-i4.h" // for ConcatClass, ConcatFwdDeclClass (ptr only)
***** IWYU_SUMMARY */