summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/CodeComplete.cpp6
-rw-r--r--clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp15
2 files changed, 18 insertions, 3 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 617046b69e9..eda6dfde7fa 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -210,7 +210,7 @@ getNonOverridenMethodCompletionResults(const DeclContext *DC, Sema *S) {
// These are stored by name to make querying fast in the later step.
llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
for (auto *Method : CR->methods()) {
- if (!Method->isVirtual())
+ if (!Method->isVirtual() || !Method->getIdentifier())
continue;
Overrides[Method->getName()].push_back(Method);
}
@@ -221,14 +221,14 @@ getNonOverridenMethodCompletionResults(const DeclContext *DC, Sema *S) {
if (!BR)
continue;
for (auto *Method : BR->methods()) {
- if (!Method->isVirtual())
+ if (!Method->isVirtual() || !Method->getIdentifier())
continue;
const auto it = Overrides.find(Method->getName());
bool IsOverriden = false;
if (it != Overrides.end()) {
for (auto *MD : it->second) {
// If the method in current body is not an overload of this virtual
- // function, that it overrides this one.
+ // function, then it overrides this one.
if (!S->IsOverload(MD, Method, false)) {
IsOverriden = true;
break;
diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
index 80e5f91430e..ca2f449bfb0 100644
--- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -1765,6 +1765,21 @@ TEST(CompletionTest, SuggestOverrides) {
Not(Contains(Labeled("void vfunc(bool param) override")))));
}
+TEST(CompletionTest, OverridesNonIdentName) {
+ // Check the completions call does not crash.
+ completions(R"cpp(
+ struct Base {
+ virtual ~Base() = 0;
+ virtual operator int() = 0;
+ virtual Base& operator+(Base&) = 0;
+ };
+
+ struct Derived : Base {
+ ^
+ };
+ )cpp");
+}
+
TEST(SpeculateCompletionFilter, Filters) {
Annotations F(R"cpp($bof^
$bol^
OpenPOWER on IntegriCloud