xref: /llvm-project/clang/test/AST/ast-dump-anonymous-class.cpp (revision fcd020d561f28a2b33b6cc12a5a0164a6d5e4172)
1 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
2 // RUN: | FileCheck -strict-whitespace %s
3 
4 struct S {
5   struct {
6     int i;
7   };
8 };
9 
accessInRegularFunction()10 int accessInRegularFunction() {
11   return S().i;
12   // CHECK: FunctionDecl {{.*}} accessInRegularFunction 'int ()'
13   // CHECK:      |   `-ReturnStmt {{.*}}
14   // CHECK-NEXT: |     `-ExprWithCleanups {{.*}} 'int'
15   // CHECK-NEXT: |       `-ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
16   // CHECK-NEXT: |         `-MemberExpr {{.*}} 'int' xvalue .i
17   // CHECK-NEXT: |           `-MemberExpr {{.*}} 'S::(anonymous struct at {{.*}})
18   // CHECK-NEXT: |             `-MaterializeTemporaryExpr {{.*}} 'S' xvalue
19   // CHECK-NEXT: |               `-CXXTemporaryObjectExpr {{.*}} 'S' 'void () noexcept' zeroing
20 }
21 
22 // AST should look the same in a function template with an unused template
23 // parameter.
24 template <class>
accessInFunctionTemplate()25 int accessInFunctionTemplate() {
26   return S().i;
27   // CHECK: FunctionDecl {{.*}} accessInFunctionTemplate 'int ()'
28   // CHECK:      |   `-ReturnStmt {{.*}}
29   // CHECK-NEXT: |     `-ExprWithCleanups {{.*}} 'int'
30   // CHECK-NEXT: |       `-ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
31   // CHECK-NEXT: |         `-MemberExpr {{.*}} 'int' xvalue .i
32   // CHECK-NEXT: |           `-MemberExpr {{.*}} 'S::(anonymous struct at {{.*}})
33   // CHECK-NEXT: |             `-MaterializeTemporaryExpr {{.*}} 'S' xvalue
34   // CHECK-NEXT: |               `-CXXTemporaryObjectExpr {{.*}} 'S' 'void () noexcept' zeroing
35 }
36 
37 // AST should look the same in an instantiation of the function template.
38 // This is a regression test: The AST used to contain the
39 // `MaterializeTemporaryExpr` in the wrong place, causing a `MemberExpr` to have
40 // a prvalue base (which is not allowed in C++).
41 template int accessInFunctionTemplate<int>();
42   // CHECK: FunctionDecl {{.*}} accessInFunctionTemplate 'int ()' explicit_instantiation_definition
43   // CHECK:          `-ReturnStmt {{.*}}
44   // CHECK-NEXT:       `-ExprWithCleanups {{.*}} 'int'
45   // CHECK-NEXT:         `-ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
46   // CHECK-NEXT:           `-MemberExpr {{.*}} 'int' xvalue .i
47   // CHECK-NEXT:             `-MemberExpr {{.*}} 'S::(anonymous struct at {{.*}})
48   // CHECK-NEXT:               `-MaterializeTemporaryExpr {{.*}} 'S' xvalue
49   // CHECK-NEXT:                 `-CXXTemporaryObjectExpr {{.*}} 'S' 'void () noexcept' zeroing
50