Skip to content

Commit 0788acb

Browse files
committed
[AST] Build recovery expressions by default for C++.
Update the existing tests. Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76696
1 parent 1e65209 commit 0788acb

File tree

16 files changed

+40
-28
lines changed

16 files changed

+40
-28
lines changed

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,9 @@ TEST(SignatureHelpTest, OpeningParen) {
11951195
int foo(int a, int b, int c);
11961196
int main() {
11971197
#define ID(X) X
1198-
ID(foo $p^( foo(10), ^ ))
1198+
// FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
1199+
// the recovery expression.
1200+
ID(foo $p^( 10, ^ ))
11991201
})cpp"};
12001202

12011203
for (auto Test : Tests) {

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template t
148148

149149
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")
150150

151-
COMPATIBLE_LANGOPT(RecoveryAST, 1, 0, "Preserve expressions in AST when encountering errors")
151+
COMPATIBLE_LANGOPT(RecoveryAST, 1, CPlusPlus, "Preserve expressions in AST when encountering errors")
152152

153153
BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers")
154154
LANGOPT(POSIXThreads , 1, 0, "POSIX thread support")

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
29092909
if (Args.hasArg(OPT_fconcepts_ts))
29102910
Diags.Report(diag::warn_fe_concepts_ts_flag);
29112911
Opts.RecoveryAST =
2912-
Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, false);
2912+
Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, Opts.CPlusPlus);
29132913
Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
29142914
Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
29152915
Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18437,8 +18437,8 @@ bool Sema::IsDependentFunctionNameExpr(Expr *E) {
1843718437

1843818438
ExprResult Sema::CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
1843918439
ArrayRef<Expr *> SubExprs) {
18440-
// FIXME: enable it for C++, RecoveryExpr is type-dependent to suppress
18441-
// bogus diagnostics and this trick does not work in C.
18440+
// RecoveryExpr is type-dependent to suppress bogus diagnostics and this trick
18441+
// does not work in C.
1844218442
// FIXME: use containsErrors() to suppress unwanted diags in C.
1844318443
if (!Context.getLangOpts().RecoveryAST)
1844418444
return ExprError();

clang/test/OpenMP/target_update_from_messages.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct S8 {
7474
#pragma omp target update from(*(this->S->i+this->S->s6[0].pp)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
7575
#pragma omp target update from(*(a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
7676
#pragma omp target update from(*(*(this->ptr)+a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
77-
#pragma omp target update from(*(this+this)) // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
77+
#pragma omp target update from(*(this+this)) // expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
7878
}
7979
};
8080

@@ -198,8 +198,8 @@ int main(int argc, char **argv) {
198198
#pragma omp target update from(**(-(*offset)+BB+*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
199199
#pragma omp target update from(**(*(*(&offset))+BB-*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
200200
#pragma omp target update from(*(x+*(y+*(**BB+BBB)+s7.i))) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
201-
#pragma omp target update from(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
202-
#pragma omp target update from(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
201+
#pragma omp target update from(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}}
202+
#pragma omp target update from(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
203203
#pragma omp target data map(to: s7.i)
204204
{
205205
#pragma omp target update from(s7.x)

clang/test/OpenMP/target_update_to_messages.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct S8 {
7777
#pragma omp target update to(*(this->S->i+this->S->s6[0].pp)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
7878
#pragma omp target update to(*(a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
7979
#pragma omp target update to(*(*(this->ptr)+a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
80-
#pragma omp target update to(*(this+this)) // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
80+
#pragma omp target update to(*(this+this)) // expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
8181
{}
8282
}
8383
};
@@ -205,8 +205,8 @@ int main(int argc, char **argv) {
205205
#pragma omp target update to(**(*offset+BB+*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
206206
#pragma omp target update to(**(*(*(&offset))+BB+*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
207207
#pragma omp target update to(*(x+*(y+*(**BB+BBB)+s7.i))) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
208-
#pragma omp target update to(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
209-
#pragma omp target update to(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
208+
#pragma omp target update to(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}}
209+
#pragma omp target update to(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
210210
{}
211211
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
212212
}

clang/test/Parser/objcxx0x-lambda-expressions.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ void f() {
1111

1212
[]; // expected-error {{expected body of lambda expression}}
1313
[=,foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}}
14-
[&this] {}; // expected-error {{cannot take the address of an rvalue of type 'C *'}}
14+
[&this] {}; // expected-error {{cannot take the address of an rvalue of type 'C *'}} \
15+
// expected-error {{expected identifier}}
1516
[] {};
1617
[=] (int i) {};
1718
[&] (int) mutable -> void {};
@@ -24,7 +25,8 @@ void f() {
2425
[foo{bar}] () {};
2526
[foo = {bar}] () {}; // expected-error {{<initializer_list>}}
2627

27-
[foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}}
28+
[foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}} \
29+
// expected-error {{expected ';'}}
2830
[foo(bar), baz] () {}; // ok
2931

3032
[foo = bar baz]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -x objective-c++ -std=c++11 %s
22

3-
void foo() { // expected-note {{to match this '{'}}
3+
void foo() {
44
int bar;
55
auto baz = [
6-
bar( // expected-note {{to match this '('}} expected-note {{to match this '('}}
6+
bar( // expected-note 2{{to match this '('}}\
7+
// expected-warning {{captures are a C++14 extension}}
78
foo_undeclared() // expected-error{{use of undeclared identifier 'foo_undeclared'}}
89
/* ) */
9-
] () { }; // expected-error{{expected ')'}}
10-
} // expected-error{{expected ')'}} expected-error {{expected ',' or ']'}} expected-error{{expected ';' at end of declaration}} expected-error{{expected '}'}}
10+
] () { }; // expected-error 2{{expected ')'}}
11+
}

clang/test/SemaCXX/builtins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ template<int (*Compare)(const char *s1, const char *s2)>
1414
int equal(const char *s1, const char *s2) {
1515
return Compare(s1, s2) == 0;
1616
}
17-
// FIXME: Our error recovery here sucks
18-
template int equal<&__builtin_strcmp>(const char*, const char*); // expected-error {{builtin functions must be directly called}} expected-error {{expected unqualified-id}} expected-error {{expected ')'}} expected-note {{to match this '('}}
17+
18+
template int equal<&__builtin_strcmp>(const char*, const char*); // expected-error {{builtin functions must be directly called}}
1919

2020
// PR13195
2121
void f2() {

clang/test/SemaCXX/cast-conversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11
1+
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11 -Wno-unused
22

33
struct R {
44
R(int);

0 commit comments

Comments
 (0)