1 /* { dg-do compile } */
2 /* { dg-options "-O -Wall" } */
3
4 /* C99 6.5.2.3 Structure and union members.
5 If the first expression has qualified type, the result has the so-qualified
6 version of the type of the designated member.
7 Based on the test from ../dfp/. */
8
9 struct s {_Fract f; const long _Fract lf;};
10 struct sv { volatile _Fract f; volatile long _Fract lf; };
11 union u
12 {
13 const long _Fract lf;
14 _Fract f;
15 const struct s cs;
16 };
17
18 struct s s;
19 struct sv sv;
20 const struct s cs;
21
22 union u u;
23 const union u cu;
24
g(struct s s)25 struct s g (struct s s)
26 {
27 return s;
28 }
29
h(union u u)30 union u h (union u u)
31 {
32 return u;
33 }
34
f()35 void f()
36 {
37 cs.f = 0.1r; /* { dg-error "assignment of member 'f' in read-only object" } */
38 cs.lf = 0.2lr; /* { dg-error "assignment of member 'lf' in read-only object" } */
39 s.lf = 0.3lr; /* { dg-error "assignment of read-only member" } */
40
41 s.f = 0.4r;
42 u.f = 0.5r;
43
44 u.lf = 0.6lr; /* { dg-error "assignment of read-only member" } */
45 u.cs.f = 0.7r; /* { dg-error "assignment of member 'f' in read-only object" } */
46 u.cs.lf = 0.8lr; /* { dg-error "assignment of member 'lf' in read-only object" } */
47
48 cu.f = 0.9r; /* { dg-error "assignment of member 'f' in read-only object" } */
49
50 cu.lf = 0.01lr; /* { dg-error "assignment of member 'lf' in read-only object" } */
51 cu.cs.f = 0.02r; /* { dg-error "assignment of member 'f' in read-only object" } */
52 cu.cs.lf = 0.03lr; /* { dg-error "assignment of member 'lf' in read-only object" } */
53
54 /* f().x is a valid postfix expression but is not an lvalue if
55 function f() returning a structure or union. */
56 g(s).f = 0.04r; /* { dg-error "lvalue required" } */
57 h(u).lf = 0.05lr; /* { dg-error "lvalue required" } */
58
59 /* Test assignment to volatile structure members. */
60 sv.f = 0.06r;
61 sv.lf = 0.07lr;
62 }
63
64