[PATCH] D77570: [clang][CodeComplete] Dont perform fallback completion for incomplete member ref
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 6 10:19:42 PDT 2020
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Clang performs expression based completion whenever it can't figure out
base of a member reference expression. It might be quite confusing in cases like
incomplete types. This patch disables that fallback.
Unfortunately `ParsePostfixExpressionSuffix` is quite tangled and this patch
adds more to it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77570
Files:
clang/lib/Parse/ParseExpr.cpp
clang/test/CodeCompletion/incomplete-member.cpp
Index: clang/test/CodeCompletion/incomplete-member.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeCompletion/incomplete-member.cpp
@@ -0,0 +1,8 @@
+struct IncompleteType;
+
+void foo() {
+ IncompleteType *f;
+ f->x;
+}
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:5:6 %s -o - | FileCheck %s -allow-empty
+// CHECK-NOT: COMPLETION:
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2018,12 +2018,19 @@
return ParsePostfixExpressionSuffix(Base);
}
- LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base,
- OpLoc, OpKind, ObjectType,
+ LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base, OpLoc,
+ OpKind, ObjectType,
MayBePseudoDestructor);
- if (LHS.isInvalid())
+ if (LHS.isInvalid()) {
+ // Clang will try to perform expression based completion as a
+ // fallback, which is confusing in case of member references. So we
+ // stop here without any completions.
+ if (Tok.is(tok::code_completion)) {
+ cutOffParsing();
+ return ExprError();
+ }
break;
-
+ }
ParseOptionalCXXScopeSpecifier(
SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
/*EnteringContext=*/false, &MayBePseudoDestructor);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77570.255395.patch
Type: text/x-patch
Size: 1645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200406/d209da5d/attachment.bin>
More information about the cfe-commits
mailing list