summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/packed4.C
blob: e5e5e2c08da3ceca01f6e28b5e690c3e0b939e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// { dg-do run { target { ! default_packed } } }
// { dg-options "-w" }

// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Jul 2003 <nathan@codesourcery.com>

// Packed fields are unsuitable for direct reference binding.

struct Unpacked { int i; };

int ConstRef (int const &p, int const *ptr, int v)
{
  if (p != v)
    return 1;
  if (&p == ptr)
    return 2;
  return 0;
}

int ConstRef (Unpacked const &p, Unpacked const *ptr, int v)
{
  if (p.i != v)
    return 1;
  if (&p == ptr)
    return 2;
  return 0;
}

int Val (int p, int v)
{
  if (p != v)
    return 1;
  return 0;
}
int Val (Unpacked p, int v)
{
  if (p.i != v)
    return 1;
  return 0;
}

struct  __attribute__ ((packed)) Packed
{
  char c;
  int i;
  Unpacked u;
  char t;
};

int Foo (Packed &p, int i, int ui)
{
  int r;
  
  if ((r = Val (p.i, i)))
    return r;
  if ((r = Val (p.u.i, ui)))
    return r + 2;
  if ((r = Val (p.u, ui)))
    return r + 4;
  
  if ((r = ConstRef (p.i, &p.i, i)))
    return r + 6;

  return 0;
}

int main ()
{
  Packed p;

  p.c = 0x12;
  p.i = 0x3456789a;
  p.u.i = 0xbcdef00f;
  p.t = 0xed;

  return Foo (p, 0x3456789a, 0xbcdef00f);
}