[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
This commit is contained in:
Kadir Cetinkaya 2020-04-06 19:13:08 +02:00
parent 97aa593a83
commit 0731132888
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
2 changed files with 19 additions and 4 deletions

View File

@ -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);

View File

@ -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: