[PATCH] D76764: [AST] Build recovery expressions for nonexistent member exprs.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 01:03:32 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa9ab11d40830: [AST] Build recovery expressions for nonexistent member exprs. (authored by hokein).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76764/new/
https://reviews.llvm.org/D76764
Files:
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang/lib/Parse/ParseExpr.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/SemaCXX/constructor-initializer.cpp
Index: clang/test/SemaCXX/constructor-initializer.cpp
===================================================================
--- clang/test/SemaCXX/constructor-initializer.cpp
+++ clang/test/SemaCXX/constructor-initializer.cpp
@@ -250,7 +250,7 @@
B(const String& s, int e=0) // expected-error {{unknown type name}}
: A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no matching constructor}} expected-error {{does not name}}
B(const B& e)
- : A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error {{does not name}} \
+ : A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error 2{{does not name}} \
// expected-error {{no member named 'm_String' in 'test3::B'}}
}
};
Index: clang/test/AST/ast-dump-recovery.cpp
===================================================================
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -83,3 +83,18 @@
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'a'
// DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
int ternary = a ? nullptr : a;
+
+// CHECK: FunctionDecl
+// CHECK-NEXT:|-ParmVarDecl {{.*}} x
+// CHECK-NEXT:`-CompoundStmt
+// CHECK-NEXT: |-RecoveryExpr {{.*}} contains-errors
+// CHECK-NEXT: | `-DeclRefExpr {{.*}} 'foo'
+// CHECK-NEXT: `-CallExpr {{.*}} contains-errors
+// CHECK-NEXT: |-RecoveryExpr {{.*}} contains-errors
+// CHECK-NEXT: | `-DeclRefExpr {{.*}} 'foo'
+// CHECK-NEXT: `-DeclRefExpr {{.*}} 'x'
+struct Foo {} foo;
+void test(int x) {
+ foo.abc;
+ foo->func(x);
+}
\ No newline at end of file
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2102,8 +2102,14 @@
OpKind, SS, TemplateKWLoc, Name,
CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
: nullptr);
- if (!LHS.isInvalid() && Tok.is(tok::less))
- checkPotentialAngleBracket(LHS);
+ if (!LHS.isInvalid()) {
+ if (Tok.is(tok::less))
+ checkPotentialAngleBracket(LHS);
+ } else if (OrigLHS && Name.isValid()) {
+ // Preserve the LHS if the RHS is an invalid member.
+ LHS = Actions.CreateRecoveryExpr(OrigLHS->getBeginLoc(),
+ Name.getEndLoc(), {OrigLHS});
+ }
break;
}
case tok::plusplus: // postfix-expression: postfix-expression '++'
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -678,7 +678,7 @@
TEST(IncludeFixerTest, NoCrashMemebrAccess) {
Annotations Test(R"cpp(// error-ok
struct X { int xyz; };
- void g() { X x; x.$[[xy]] }
+ void g() { X x; x.$[[xy]]; }
)cpp");
auto TU = TestTU::withCode(Test.code());
auto Index = buildIndexWithSymbol(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76764.252764.patch
Type: text/x-patch
Size: 3086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200326/5714383d/attachment.bin>
More information about the cfe-commits
mailing list