[PATCH] D88964: [clangd] Add a missing include-fixer test for incomplete_type, NFC.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 06:30:02 PDT 2020


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: clang.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Also sort the list to make it easier to verify with the implementation
code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88964

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -702,15 +702,17 @@
   Annotations Test(R"cpp(// error-ok
 $insert[[]]namespace ns {
   class X;
-  $nested[[X::]]Nested n;
 }
 class Y : $base[[public ns::X]] {};
 int main() {
   ns::X *x;
+  auto& $type[[[]]a] = *x;
   x$access[[->]]f();
+  $nested[[ns::X::]]Nested n;
 }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
+  TU.ExtraArgs.push_back("-std=c++17");
   auto Index = buildIndexWithSymbol(
       {SymbolWithHeader{"ns::X", "unittest:///x.h", "\"x.h\""}});
   TU.ExternalIndex = Index.get();
@@ -718,18 +720,24 @@
   EXPECT_THAT(
       TU.build().getDiagnostics(),
       UnorderedElementsAre(
-          AllOf(Diag(Test.range("nested"),
-                     "incomplete type 'ns::X' named in nested name specifier"),
-                DiagName("incomplete_nested_name_spec"),
-                WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
-                            "Add include \"x.h\" for symbol ns::X"))),
           AllOf(Diag(Test.range("base"), "base class has incomplete type"),
                 DiagName("incomplete_base_class"),
                 WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
                             "Add include \"x.h\" for symbol ns::X"))),
+          AllOf(
+              Diag(Test.range("type"),
+                   "incomplete type 'ns::X' where a complete type is required"),
+              DiagName("incomplete_type"),
+              WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+                          "Add include \"x.h\" for symbol ns::X"))),
           AllOf(Diag(Test.range("access"),
                      "member access into incomplete type 'ns::X'"),
                 DiagName("incomplete_member_access"),
+                WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+                            "Add include \"x.h\" for symbol ns::X"))),
+          AllOf(Diag(Test.range("nested"),
+                     "incomplete type 'ns::X' named in nested name specifier"),
+                DiagName("incomplete_nested_name_spec"),
                 WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
                             "Add include \"x.h\" for symbol ns::X")))));
 }
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===================================================================
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -68,9 +68,9 @@
 std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
                                    const clang::Diagnostic &Info) const {
   switch (Info.getID()) {
+  case diag::err_incomplete_base_class:
   case diag::err_incomplete_type:
   case diag::err_incomplete_member_access:
-  case diag::err_incomplete_base_class:
   case diag::err_incomplete_nested_name_spec:
     // Incomplete type diagnostics should have a QualType argument for the
     // incomplete type.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88964.296659.patch
Type: text/x-patch
Size: 3150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201007/5fa22ffe/attachment.bin>


More information about the cfe-commits mailing list