diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/fixed-point/struct-union.c | |
download | cbb-gcc-4.6.4-upstream.tar.bz2 cbb-gcc-4.6.4-upstream.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/fixed-point/struct-union.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/fixed-point/struct-union.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/fixed-point/struct-union.c b/gcc/testsuite/gcc.dg/fixed-point/struct-union.c new file mode 100644 index 000000000..93ed260b0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fixed-point/struct-union.c @@ -0,0 +1,63 @@ +/* { dg-do compile } */ +/* { dg-options "-O -Wall" } */ + +/* C99 6.5.2.3 Structure and union members. + If the first expression has qualified type, the result has the so-qualified + version of the type of the designated member. + Based on the test from ../dfp/. */ + +struct s {_Fract f; const long _Fract lf;}; +struct sv { volatile _Fract f; volatile long _Fract lf; }; +union u +{ + const long _Fract lf; + _Fract f; + const struct s cs; +}; + +struct s s; +struct sv sv; +const struct s cs; + +union u u; +const union u cu; + +struct s g (struct s s) +{ + return s; +} + +union u h (union u u) +{ + return u; +} + +void f() +{ + cs.f = 0.1r; /* { dg-error "assignment of member 'f' in read-only object" } */ + cs.lf = 0.2lr; /* { dg-error "assignment of member 'lf' in read-only object" } */ + s.lf = 0.3lr; /* { dg-error "assignment of read-only member" } */ + + s.f = 0.4r; + u.f = 0.5r; + + u.lf = 0.6lr; /* { dg-error "assignment of read-only member" } */ + u.cs.f = 0.7r; /* { dg-error "assignment of member 'f' in read-only object" } */ + u.cs.lf = 0.8lr; /* { dg-error "assignment of member 'lf' in read-only object" } */ + + cu.f = 0.9r; /* { dg-error "assignment of member 'f' in read-only object" } */ + + cu.lf = 0.01lr; /* { dg-error "assignment of member 'lf' in read-only object" } */ + cu.cs.f = 0.02r; /* { dg-error "assignment of member 'f' in read-only object" } */ + cu.cs.lf = 0.03lr; /* { dg-error "assignment of member 'lf' in read-only object" } */ + + /* f().x is a valid postfix expression but is not an lvalue if + function f() returning a structure or union. */ + g(s).f = 0.04r; /* { dg-error "lvalue required" } */ + h(u).lf = 0.05lr; /* { dg-error "lvalue required" } */ + + /* Test assignment to volatile structure members. */ + sv.f = 0.06r; + sv.lf = 0.07lr; +} + |