Debian Codegraph @

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

raw
1 // { dg-do compile { target c++11 } }
2
3 template <typename To, typename From>
4 constexpr To
5 bit_cast (const From &from)
6 {
7 return __builtin_bit_cast (To, from);
8 }
9 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'U' is a union type" "U" { target *-*-* } 7 }
10 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'const U' is a union type" "const U" { target *-*-* } 7 }
11 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'B' contains a union type" "B" { target *-*-* } 7 }
12 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'char\\\*' is a pointer type" "char ptr" { target *-*-* } 7 }
13 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'const int\\\*' is a pointer type" "const int ptr" { target *-*-* } 7 }
14 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'C' contains a pointer type" "C" { target *-*-* } 7 }
15 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'const C' contains a pointer type" "const C" { target *-*-* } 7 }
16 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'int D::\\\*' is a pointer to member type" "ptrmem 1" { target *-*-* } 7 }
17 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'int \\\(D::\\\*\\\)\\\(\\\) const' is a pointer to member type" "ptrmem 2" { target *-*-* } 7 }
18 // { dg-error "'__builtin_bit_cast' is not a constant expression because 'int \\\(D::\\\*\\\)\\\(\\\)' is a pointer to member type" "ptrmem 3" { target *-*-* } 7 }
19
20 union U { int u; };
21 struct A { int a; U b; };
22 struct B : public A { int c; };
23 struct C { const int *p; };
24 constexpr int a[] = { 1, 2, 3 };
25 constexpr const int *b = &a[0];
26 constexpr C c = { b };
27 struct D { int d; constexpr int foo () const { return 1; } };
28 constexpr int D::*d = &D::d;
29 constexpr int (D::*e) () const = &D::foo;
30 struct E { __INTPTR_TYPE__ e, f; };
31 constexpr E f = { 1, 2 };
32 constexpr U g { 0 };
33
34 constexpr auto z = bit_cast <U> (0);
35 constexpr auto y = bit_cast <int> (g);
36 constexpr auto x = bit_cast <B> (a);
37 constexpr auto w = bit_cast <char *> ((__INTPTR_TYPE__) 0);
38 constexpr auto v = bit_cast <__UINTPTR_TYPE__> (b);
39 constexpr auto u = bit_cast <C> ((__INTPTR_TYPE__) 0);
40 constexpr auto t = bit_cast <__INTPTR_TYPE__> (c);
41 constexpr auto s = bit_cast <__INTPTR_TYPE__> (d);
42 constexpr auto r = bit_cast <E> (e);
43 constexpr auto q = bit_cast <int D::*> ((__INTPTR_TYPE__) 0);
44 constexpr auto p = bit_cast <int (D::*) ()> (f);