Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/bit-cast2.C

raw
1 // { dg-do compile }
2
3 struct S { ~S (); int s; };
4 S s;
5 struct V; // { dg-message "forward declaration of 'struct V'" }
6 extern V v; // { dg-error "'v' has incomplete type" }
7 extern V *p;
8 struct U { int a, b; };
9 U u;
10
11 void
12 foo (int *q)
13 {
14 __builtin_bit_cast (int, s); // { dg-error "'__builtin_bit_cast' source type 'S' is not trivially copyable" }
15 __builtin_bit_cast (S, 0); // { dg-error "'__builtin_bit_cast' destination type 'S' is not trivially copyable" }
16 __builtin_bit_cast (int &, q); // { dg-error "'__builtin_bit_cast' destination type 'int&' is not trivially copyable" }
17 __builtin_bit_cast (int [1], 0); // { dg-error "'__builtin_bit_cast' destination type \[^\n\r]* is an array type" }
18 __builtin_bit_cast (V, 0); // { dg-error "invalid use of incomplete type 'struct V'" }
19 __builtin_bit_cast (int, v);
20 __builtin_bit_cast (int, *p); // { dg-error "invalid use of incomplete type 'struct V'" }
21 __builtin_bit_cast (U, 0); // { dg-error "'__builtin_bit_cast' source size '\[0-9]*' not equal to destination type size '\[0-9]*'" }
22 __builtin_bit_cast (int, u); // { dg-error "'__builtin_bit_cast' source size '\[0-9]*' not equal to destination type size '\[0-9]*'" }
23 }
24
25 template <int N>
26 void
27 bar (int *q)
28 {
29 __builtin_bit_cast (int, s); // { dg-error "'__builtin_bit_cast' source type 'S' is not trivially copyable" }
30 __builtin_bit_cast (S, 0); // { dg-error "'__builtin_bit_cast' destination type 'S' is not trivially copyable" }
31 __builtin_bit_cast (int &, q); // { dg-error "'__builtin_bit_cast' destination type 'int&' is not trivially copyable" }
32 __builtin_bit_cast (int [1], 0); // { dg-error "'__builtin_bit_cast' destination type \[^\n\r]* is an array type" }
33 __builtin_bit_cast (V, 0); // { dg-error "invalid use of incomplete type 'struct V'" }
34 __builtin_bit_cast (int, *p); // { dg-error "invalid use of incomplete type 'struct V'" }
35 __builtin_bit_cast (U, 0); // { dg-error "'__builtin_bit_cast' source size '\[0-9]*' not equal to destination type size '\[0-9]*'" }
36 __builtin_bit_cast (int, u); // { dg-error "'__builtin_bit_cast' source size '\[0-9]*' not equal to destination type size '\[0-9]*'" }
37 }
38
39 template <typename T1, typename T2, typename T3, typename T4>
40 void
41 baz (T3 s, T4 *p, T1 *q)
42 {
43 __builtin_bit_cast (int, s); // { dg-error "'__builtin_bit_cast' source type 'S' is not trivially copyable" }
44 __builtin_bit_cast (T3, 0); // { dg-error "'__builtin_bit_cast' destination type 'S' is not trivially copyable" }
45 __builtin_bit_cast (T1 &, q); // { dg-error "'__builtin_bit_cast' destination type 'int&' is not trivially copyable" }
46 __builtin_bit_cast (T2, 0); // { dg-error "'__builtin_bit_cast' destination type \[^\n\r]* is an array type" }
47 __builtin_bit_cast (T4, 0); // { dg-error "invalid use of incomplete type 'struct V'" }
48 __builtin_bit_cast (int, *p); // { dg-error "invalid use of incomplete type 'struct V'" }
49 __builtin_bit_cast (U, (T1) 0); // { dg-error "'__builtin_bit_cast' source size '\[0-9]*' not equal to destination type size '\[0-9]*'" }
50 __builtin_bit_cast (T1, u); // { dg-error "'__builtin_bit_cast' source size '\[0-9]*' not equal to destination type size '\[0-9]*'" }
51 }
52
53 void
54 qux (int *q)
55 {
56 baz <int, int [1], S, V> (s, p, q);
57 }