xref: /llvm-project/clang/test/AST/ast-dump-expr-errors.cpp (revision 1a0d466081318adfc356917fccc5116f9031ef7e)
1733edf97SHaojian Wu // RUN: not %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 -ast-dump -frecovery-ast %s | FileCheck -strict-whitespace %s
2733edf97SHaojian Wu 
3733edf97SHaojian Wu // Check errors flag is set for RecoveryExpr.
4733edf97SHaojian Wu //
5733edf97SHaojian Wu // CHECK:     VarDecl {{.*}} a
6733edf97SHaojian Wu // CHECK-NEXT:`-RecoveryExpr {{.*}} contains-errors
7733edf97SHaojian Wu // CHECK-NEXT:  `-UnresolvedLookupExpr {{.*}} 'bar'
8733edf97SHaojian Wu int a = bar();
9733edf97SHaojian Wu 
10733edf97SHaojian Wu // The flag propagates through more complicated calls.
11733edf97SHaojian Wu //
12733edf97SHaojian Wu // CHECK:     VarDecl {{.*}} b
13733edf97SHaojian Wu // CHECK-NEXT:`-CallExpr {{.*}} contains-errors
14733edf97SHaojian Wu // CHECK-NEXT:  |-UnresolvedLookupExpr {{.*}} 'bar'
15733edf97SHaojian Wu // CHECK-NEXT:  |-RecoveryExpr {{.*}} contains-errors
16733edf97SHaojian Wu // CHECK-NEXT:  | `-UnresolvedLookupExpr {{.*}} 'baz'
17733edf97SHaojian Wu // CHECK-NEXT:   `-RecoveryExpr {{.*}} contains-errors
18733edf97SHaojian Wu // CHECK-NEXT:     `-UnresolvedLookupExpr {{.*}} 'qux'
19733edf97SHaojian Wu int b = bar(baz(), qux());
20733edf97SHaojian Wu 
21733edf97SHaojian Wu // Also propagates through more complicated expressions.
22733edf97SHaojian Wu //
23733edf97SHaojian Wu // CHECK:     |-VarDecl {{.*}} c
24733edf97SHaojian Wu // CHECK-NEXT:| `-BinaryOperator {{.*}} '<dependent type>' contains-errors '*'
25733edf97SHaojian Wu // CHECK-NEXT:|   |-UnaryOperator {{.*}} '<dependent type>' contains-errors prefix '&'
26733edf97SHaojian Wu // CHECK-NEXT:|   | `-ParenExpr {{.*}} '<dependent type>' contains-errors
27733edf97SHaojian Wu // CHECK-NEXT:|   |   `-BinaryOperator {{.*}} '<dependent type>' contains-errors '+'
28733edf97SHaojian Wu // CHECK-NEXT:|   |     |-RecoveryExpr {{.*}} '<dependent type>' contains-errors
29733edf97SHaojian Wu // CHECK-NEXT:|   |     | `-UnresolvedLookupExpr {{.*}} 'bar'
30733edf97SHaojian Wu // CHECK-NEXT:|   |     `-RecoveryExpr {{.*}} '<dependent type>' contains-errors
31733edf97SHaojian Wu // CHECK-NEXT:|   |       `-UnresolvedLookupExpr {{.*}} 'baz'
32733edf97SHaojian Wu int c = &(bar() + baz()) * 10;
33733edf97SHaojian Wu 
34733edf97SHaojian Wu // Errors flag propagates even when type is not dependent anymore.
35733edf97SHaojian Wu // CHECK:     |-VarDecl {{.*}} d
36733edf97SHaojian Wu // CHECK-NEXT:| `-CXXStaticCastExpr {{.*}} 'int' contains-errors
37733edf97SHaojian Wu // CHECK-NEXT:|   `-BinaryOperator {{.*}} '<dependent type>' contains-errors '+'
38733edf97SHaojian Wu // CHECK-NEXT:|     |-RecoveryExpr {{.*}} '<dependent type>' contains-errors
39733edf97SHaojian Wu // CHECK-NEXT:|     | `-UnresolvedLookupExpr {{.*}} 'bar'
40733edf97SHaojian Wu // CHECK-NEXT:|     `-IntegerLiteral {{.*}} 1
41733edf97SHaojian Wu int d = static_cast<int>(bar() + 1);
42733edf97SHaojian Wu 
43*6f428e09SHaojian Wu 
44*6f428e09SHaojian Wu // Error type should result in an invalid decl.
45*6f428e09SHaojian Wu // CHECK: -VarDecl {{.*}} invalid f 'decltype(<recovery-expr>(bar))'
46*6f428e09SHaojian Wu decltype(bar()) f;
47