[AST] Use recovery-expr to preserve incomplete-type-member-access expression.

Fixes https://github.com/clangd/clangd/issues/502

Differential Revision: https://reviews.llvm.org/D116922
This commit is contained in:
Haojian Wu 2022-01-07 22:55:58 +01:00
parent c44d521b30
commit abe3003ead
3 changed files with 14 additions and 3 deletions

View File

@ -7410,8 +7410,10 @@ ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, Expr *Base,
// the member function body. // the member function body.
if (!BaseType->isDependentType() && if (!BaseType->isDependentType() &&
!isThisOutsideMemberFunctionBody(BaseType) && !isThisOutsideMemberFunctionBody(BaseType) &&
RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access)) RequireCompleteType(OpLoc, BaseType,
return ExprError(); diag::err_incomplete_member_access)) {
return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
}
// C++ [basic.lookup.classref]p2: // C++ [basic.lookup.classref]p2:
// If the id-expression in a class member access (5.2.5) is an // If the id-expression in a class member access (5.2.5) is an

View File

@ -121,6 +121,16 @@ void test(int x) {
foo->func(x); foo->func(x);
} }
void AccessIncompleteClass() {
struct Forward;
Forward* ptr;
// CHECK: CallExpr {{.*}} '<dependent type>'
// CHECK-NEXT: `-CXXDependentScopeMemberExpr {{.*}} '<dependent type>'
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' contains-errors
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Forward *'
ptr->method();
}
struct Foo2 { struct Foo2 {
double func(); double func();
class ForwardClass; class ForwardClass;

View File

@ -169,7 +169,6 @@ struct S
#pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error {{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated type 'U'}} #pragma omp declare reduction (xxx : U, S : bar(omp_in)) // expected-error {{non-const lvalue reference to type 'S<1>' cannot bind to a value of unrelated type 'U'}}
static void bar(S &x); // expected-note {{passing argument to parameter 'x' here}} static void bar(S &x); // expected-note {{passing argument to parameter 'x' here}}
}; };
// expected-warning@+2 {{extra tokens at the end of '#pragma omp declare reduction' are ignored}}
// expected-note@+1 {{in instantiation of template class 'S<1>' requested here}} // expected-note@+1 {{in instantiation of template class 'S<1>' requested here}}
#pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in)) #pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))