[CodeComplete] Fix a crash in preferred type and signature help
Summary: Null type pointers could be dereferenced in some cases.
Reviewers: kadircet, sammccall
Reviewed By: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71329
diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp
index ab1792b..a9441a6 100644
--- a/clang/unittests/Sema/CodeCompleteTest.cpp
+++ b/clang/unittests/Sema/CodeCompleteTest.cpp
@@ -481,4 +481,12 @@
)cpp";
EXPECT_THAT(collectPreferredTypes(Code), Each("vector<int>"));
}
+
+TEST(PreferredTypeTest, NoCrashOnInvalidTypes) {
+ StringRef Code = R"cpp(
+ auto x = decltype(&1)(^);
+ auto y = new decltype(&1)(^);
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("NULL TYPE"));
+}
} // namespace