[clang] bc31be7 - [clang][CodeComplete] Handle deref operator in getApproximateType (#86466)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 25 20:54:43 PDT 2024
Author: Nathan Ridge
Date: 2024-03-25T23:54:40-04:00
New Revision: bc31be7949a3d5382be0e15e3957fa957da9de45
URL: https://github.com/llvm/llvm-project/commit/bc31be7949a3d5382be0e15e3957fa957da9de45
DIFF: https://github.com/llvm/llvm-project/commit/bc31be7949a3d5382be0e15e3957fa957da9de45.diff
LOG: [clang][CodeComplete] Handle deref operator in getApproximateType (#86466)
This allows completing after `(*this).` in a dependent context.
Fixes https://github.com/clangd/clangd/issues/1952
Added:
Modified:
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/member-access.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 73e6baa5278262..83ebcaf9e765a7 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"
@@ -5678,6 +5679,10 @@ 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