Debian Codegraph @

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

raw
1 // PR c++/98329
2 // { dg-do compile { target c++20 } }
3
4 template <typename To, typename From>
5 constexpr To
6 foo (const From &from)
7 {
8 return __builtin_bit_cast (To, &from);
9 }
10
11 template <typename To, typename From>
12 constexpr To
13 bar (const From &from)
14 {
15 return __builtin_bit_cast (To, *from);
16 }
17
18 template <typename To, typename From>
19 constexpr To
20 baz (const From &from)
21 {
22 return __builtin_bit_cast (To, **from);
23 }
24
25 template <typename To, typename From>
26 constexpr To
27 qux (const From &from)
28 {
29 return __builtin_bit_cast (To, -from);
30 }
31
32 void
33 test ()
34 {
35 int i = 0;
36 int *j = &i;
37 int **k = &j;
38 foo <char *> (i);
39 bar <int> (j);
40 baz <int> (k);
41 qux <int> (i);
42 }