[clang] 0731132 - [clang][CodeComplete] Dont perform fallback completion for incomplete member ref
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 6 11:08:35 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-04-06T20:08:24+02:00
New Revision: 0731132888a0219179fdb4303cd690a6687cc130
URL: https://github.com/llvm/llvm-project/commit/0731132888a0219179fdb4303cd690a6687cc130
DIFF: https://github.com/llvm/llvm-project/commit/0731132888a0219179fdb4303cd690a6687cc130.diff
LOG: [clang][CodeComplete] Dont perform fallback completion for incomplete member ref
Summary:
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.
Reviewers: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77570
Added:
clang/test/CodeCompletion/incomplete-member.cpp
Modified:
clang/lib/Parse/ParseExpr.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index fc07cfe5ad03..0c6939b04319 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2018,12 +2018,19 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
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);
diff --git a/clang/test/CodeCompletion/incomplete-member.cpp b/clang/test/CodeCompletion/incomplete-member.cpp
new file mode 100644
index 000000000000..f86b48887e02
--- /dev/null
+++ b/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:
More information about the cfe-commits
mailing list