xref: /llvm-project/clang/test/AST/ast-dump-APValue-anon-union.cpp (revision 5ae5774fb0b5cac11af479b0905dfdd5255b4047)
1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
3 // RUN:            -ast-dump %s -ast-dump-filter Test \
4 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
5 //
6 // Test with serialization:
7 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 -emit-pch -o %t %s
8 // RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
9 // RUN:           -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \
10 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
11 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
12 
13 struct S0 {
14   union {
15     int i = 42;
16   };
17 };
18 
19 union U0 {
20   union {
21     float f = 3.1415f;
22   };
23 };
24 
25 union U1 {
26   union {
27     float f;
28   };
29 };
30 
Test()31 void Test() {
32   constexpr S0 s0{};
33   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s0 'const S0' constexpr listinit
34   // CHECK-NEXT:  |   |-value: Struct
35   // CHECK-NEXT:  |   | `-field: Union .i Int 42
36 
37   constexpr U0 u0a{};
38   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} u0a 'const U0' constexpr listinit
39   // CHECK-NEXT:  |   |-value: Union .U0::(anonymous union at {{.*}}) Union .f Float 3.141500e+00
40 
41   constexpr U0 u0b{3.1415f};
42   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} u0b 'const U0' constexpr listinit
43   // CHECK-NEXT:  |   |-value: Union .U0::(anonymous union at {{.*}}) Union .f Float 3.141500e+00
44 
45   constexpr U1 u1a{};
46   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} u1a 'const U1' constexpr listinit
47   // CHECK-NEXT:  |   |-value: Union .U1::(anonymous union at {{.*}}) Union .f Float 0.000000e+00
48 
49   constexpr U1 u1b{3.1415f};
50   // CHECK:    `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} u1b 'const U1' constexpr listinit
51   // CHECK-NEXT:      |-value: Union .U1::(anonymous union at {{.*}}) Union .f Float 3.141500e+00
52 }
53