[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 24 23:15:16 PDT 2024
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/86466
This allows completing after `(*this).` in a dependent context.
Fixes https://github.com/clangd/clangd/issues/1952
>From 6cac58d2e5c3c7effc0f0cc01c1368b9ddd6c21a Mon Sep 17 00:00:00 2001
From: Nathan Ridge <zeratul976 at hotmail.com>
Date: Mon, 25 Mar 2024 02:14:00 -0400
Subject: [PATCH] [clang][CodeComplete] Handle deref operator in
getApproximateType
This allows completing after `(*this).` in a dependent context.
Fixes https://github.com/clangd/clangd/issues/1952
---
clang/lib/Sema/SemaCodeComplete.cpp | 6 ++++++
clang/test/CodeCompletion/member-access.cpp | 20 ++++++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c44be0df9b0a85..0e44b0f444ed73 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -20,6 +20,7 @@
#include "clang/AST/ExprConcepts.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OperationKinds.h"
#include "clang/AST/QualTypeNames.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Type.h"
@@ -5674,6 +5675,11 @@ QualType getApproximateType(const Expr *E) {
return getApproximateType(VD->getInit());
}
}
+ if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
+ if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
+ return UO->getSubExpr()->getType()->getPointeeType();
+ }
+ }
return Unresolved;
}
diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp
index 474b909ab11592..9f8c21c0bca6de 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -348,7 +348,23 @@ namespace function_can_be_call {
T foo(U, V);
};
- &S::f
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
+ void test() {
+ &S::f
+ }
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:352:9 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
// CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#T#]foo<<#typename T#>, <#typename U#>>(<#U#>, <#V#>)
}
+
+namespace deref_dependent_this {
+template <typename T>
+class A {
+ int field;
+
+ void function() {
+ (*this).field;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:364:13 %s -o - | FileCheck -check-prefix=CHECK-DEREF-THIS %s
+// CHECK-DEREF-THIS: field : [#int#]field
+// CHECK-DEREF-THIS: [#void#]function()
+ }
+};
+}
More information about the cfe-commits
mailing list