OSDN Git Service

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