summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUladzislau Paulovich <ulad@fb.com>2019-09-11 23:17:44 +0100
committerKim Gräsman <kim.grasman@gmail.com>2019-09-30 21:55:51 +0200
commit981001cfee126d2beea2dad338c4c6dd9b251cbb (patch)
tree4cd205b2a13081f0c79a8e749e9dbf6bef7c2c80
parent919f21b5ffd85513503547b52084cc3f1eea732a (diff)
Fix final class forward-declaration bug
-rw-r--r--iwyu_output.cc10
-rwxr-xr-xrun_iwyu_tests.py1
-rw-r--r--tests/cxx/fwd_decl_final-d1.h19
-rw-r--r--tests/cxx/fwd_decl_final.cc31
-rw-r--r--tests/cxx/fwd_decl_final.h36
5 files changed, 97 insertions, 0 deletions
diff --git a/iwyu_output.cc b/iwyu_output.cc
index ec936c5..c248428 100644
--- a/iwyu_output.cc
+++ b/iwyu_output.cc
@@ -452,10 +452,20 @@ string MungedForwardDeclareLineForTemplates(const TemplateDecl* decl) {
line = Split(line, " :", 2)[0];
// Get rid of the template body, if any (true if no superclasses).
line = Split(line, " {", 2)[0];
+
+ // Remove "final" specifier which isn't needed for forward
+ // declarations.
+ const char kFinalSpecifier[] = " final ";
+ string::size_type final_pos = line.find(kFinalSpecifier);
+ if (final_pos != string::npos) {
+ line.replace(final_pos, sizeof(kFinalSpecifier), " ");
+ }
+
// The template name is now the last word on the line. Replace it
// by its fully-qualified form.
const string::size_type name = line.rfind(' ');
CHECK_(name != string::npos && "Unexpected printable template-type");
+
return PrintForwardDeclare(decl, line.substr(0, name), GlobalFlags().cxx17ns);
}
diff --git a/run_iwyu_tests.py b/run_iwyu_tests.py
index 24c8f02..2675bd6 100755
--- a/run_iwyu_tests.py
+++ b/run_iwyu_tests.py
@@ -151,6 +151,7 @@ class OneIwyuTest(unittest.TestCase):
'forward_declare_in_macro.cc': ['.'],
'fullinfo_for_templates.cc': ['.'],
'fwd_decl_class_template.cc': ['.'],
+ 'fwd_decl_final.cc': ['.'],
'fwd_decl_static_member.cc': ['.'],
'fwd_decl_with_instantiation.cc': ['.'],
'header_in_subdir.cc': ['.'],
diff --git a/tests/cxx/fwd_decl_final-d1.h b/tests/cxx/fwd_decl_final-d1.h
new file mode 100644
index 0000000..c3f3a28
--- /dev/null
+++ b/tests/cxx/fwd_decl_final-d1.h
@@ -0,0 +1,19 @@
+//===--- fwd_decl_final-d1.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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_FWD_DECL_FINAL_D1_H_
+#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_FWD_DECL_FINAL_D1_H_
+
+
+template <typename T>
+class FinalTemplate final {};
+
+class FinalClass final {};
+
+#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_FWD_DECL_FINAL_D1_H_
diff --git a/tests/cxx/fwd_decl_final.cc b/tests/cxx/fwd_decl_final.cc
new file mode 100644
index 0000000..c40bdf5
--- /dev/null
+++ b/tests/cxx/fwd_decl_final.cc
@@ -0,0 +1,31 @@
+//===--- fwd_decl_final.cc - 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.
+//
+//===----------------------------------------------------------------------===//
+
+#include "tests/cxx/fwd_decl_final.h"
+
+void FwdDeclFinal::testFinalTemplate(FinalTemplate<int>* finalTemplate) {
+}
+
+void FwdDeclFinal::testFinalClass(FinalClass* finalClass) {
+}
+
+/**** IWYU_SUMMARY
+
+tests/cxx/fwd_decl_final.cc should add these lines:
+class FinalClass;
+template <typename T> class FinalTemplate;
+
+tests/cxx/fwd_decl_final.cc should remove these lines:
+
+The full include-list for tests/cxx/fwd_decl_final.cc:
+#include "tests/cxx/fwd_decl_final.h"
+class FinalClass;
+template <typename T> class FinalTemplate;
+
+***** IWYU_SUMMARY */
diff --git a/tests/cxx/fwd_decl_final.h b/tests/cxx/fwd_decl_final.h
new file mode 100644
index 0000000..103bcd5
--- /dev/null
+++ b/tests/cxx/fwd_decl_final.h
@@ -0,0 +1,36 @@
+//===--- fwd_decl_final.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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_FWD_DECL_FINAL_H_
+#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_FWD_DECL_FINAL_H_
+
+#include "tests/cxx/fwd_decl_final-d1.h"
+
+class FwdDeclFinal {
+public:
+ void testFinalTemplate(FinalTemplate<int>* finalTemplate);
+ void testFinalClass(FinalClass* finalClass);
+};
+
+#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_FWD_DECL_FINAL_H_
+
+/**** IWYU_SUMMARY
+
+tests/cxx/fwd_decl_final.h should add these lines:
+class FinalClass;
+template <typename T> class FinalTemplate;
+
+tests/cxx/fwd_decl_final.h should remove these lines:
+- #include "tests/cxx/fwd_decl_final-d1.h" // lines XX-XX
+
+The full include-list for tests/cxx/fwd_decl_final.h:
+class FinalClass;
+template <typename T> class FinalTemplate;
+
+***** IWYU_SUMMARY */