[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 24 23:15:43 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Nathan Ridge (HighCommander4)
<details>
<summary>Changes</summary>
This allows completing after `(*this).` in a dependent context.
Fixes https://github.com/clangd/clangd/issues/1952
---
Full diff: https://github.com/llvm/llvm-project/pull/86466.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+6)
- (modified) clang/test/CodeCompletion/member-access.cpp (+18-2)
``````````diff
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()
+ }
+};
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/86466
More information about the cfe-commits
mailing list