OSDN Git Service

cp/ChangeLog:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / ext / packed4.C
1 // { dg-do run }
2
3 // Copyright (C) 2003 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 15 Jul 2003 <nathan@codesourcery.com>
5
6 // Packed fields are unsuitable for direct reference binding.
7
8 struct Unpacked { int i; };
9
10 int ConstRef (int const &p, int const *ptr, int v)
11 {
12   if (p != v)
13     return 1;
14   if (&p == ptr)
15     return 2;
16   return 0;
17 }
18
19 int ConstRef (Unpacked const &p, Unpacked const *ptr, int v)
20 {
21   if (p.i != v)
22     return 1;
23   if (&p == ptr)
24     return 2;
25   return 0;
26 }
27
28 int Val (int p, int v)
29 {
30   if (p != v)
31     return 1;
32   return 0;
33 }
34 int Val (Unpacked p, int v)
35 {
36   if (p.i != v)
37     return 1;
38   return 0;
39 }
40
41 struct  __attribute__ ((packed)) Packed
42 {
43   char c;
44   int i;
45   Unpacked u;
46   char t;
47 };
48
49 int Foo (Packed &p, int i, int ui)
50 {
51   int r;
52   
53   if ((r = Val (p.i, i)))
54     return r;
55   if ((r = Val (p.u.i, ui)))
56     return r + 2;
57   if ((r = Val (p.u, ui)))
58     return r + 4;
59   
60   if ((r = ConstRef (p.i, &p.i, i)))
61     return r + 6;
62
63   return 0;
64 }
65
66 int main ()
67 {
68   Packed p;
69
70   p.c = 0x12;
71   p.i = 0x3456789a;
72   p.u.i = 0xbcdef00f;
73   p.t = 0xed;
74
75   return Foo (p, 0x3456789a, 0xbcdef00f);
76 }