[clang] abe3003 - [AST] Use recovery-expr to preserve incomplete-type-member-access expression.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 10 03:45:36 PST 2022
Author: Haojian Wu
Date: 2022-01-10T12:45:20+01:00
New Revision: abe3003ead808518190d1e9717495735786938d3
URL: https://github.com/llvm/llvm-project/commit/abe3003ead808518190d1e9717495735786938d3
DIFF: https://github.com/llvm/llvm-project/commit/abe3003ead808518190d1e9717495735786938d3.diff
LOG: [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
Added:
Modified:
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/OpenMP/declare_reduction_messages.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4c6a96acdb91..b34b744d7312 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7410,8 +7410,10 @@ ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, Expr *Base,
// the member function body.
if (!BaseType->isDependentType() &&
!isThisOutsideMemberFunctionBody(BaseType) &&
- RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
- return ExprError();
+ RequireCompleteType(OpLoc, BaseType,
+ diag::err_incomplete_member_access)) {
+ return CreateRecoveryExpr(Base->getBeginLoc(), Base->getEndLoc(), {Base});
+ }
// C++ [basic.lookup.classref]p2:
// If the id-expression in a class member access (5.2.5) is an
diff --git a/clang/test/AST/ast-dump-recovery.cpp b/clang/test/AST/ast-dump-recovery.cpp
index c196f629bad9..0bdd726ab3ce 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -121,6 +121,16 @@ void test(int 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 {
double func();
class ForwardClass;
diff --git a/clang/test/OpenMP/declare_reduction_messages.cpp b/clang/test/OpenMP/declare_reduction_messages.cpp
index b1e59591d998..38a5d766eead 100644
--- a/clang/test/OpenMP/declare_reduction_messages.cpp
+++ b/clang/test/OpenMP/declare_reduction_messages.cpp
@@ -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'}}
static void bar(S &x); // expected-note {{passing argument to parameter 'x' here}}
};
-// expected-warning at +2 {{extra tokens at the end of '#pragma omp declare reduction' are ignored}}
// expected-note at +1 {{in instantiation of template class 'S<1>' requested here}}
#pragma omp declare reduction (bar : S<1> : omp_out.foo(omp_in))
More information about the cfe-commits
mailing list