File: composite-type.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (55 lines) | stat: -rw-r--r-- 2,122 bytes parent folder | download | duplicates (4)
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
/* { dg-do compile } */
/* { dg-options "-O -Wall -ftrack-macro-expansion=0" } */

/* C99 6.2.7: Compatible type and composite type.  */

#define DECIMAL_COMPOSITE_DECL(TYPE) \
  _Decimal##TYPE g1_##TYPE(); \
  _Decimal##TYPE g2_##TYPE(); \
  _Decimal##TYPE (*h1_##TYPE)[2]; \
  _Decimal##TYPE (*h2_##TYPE)[3]; \
  _Decimal##TYPE (*h3_##TYPE)[4]; \
  _Decimal##TYPE f1_##TYPE(_Decimal##TYPE(*)()); \
  _Decimal##TYPE f1_##TYPE(_Decimal##TYPE(*)(_Decimal##TYPE*)); \
  _Decimal##TYPE f1_##TYPE (_Decimal##TYPE(*g)(_Decimal##TYPE*)) \
   { \
     _Decimal##TYPE d##TYPE; \
     d##TYPE = ((_Decimal##TYPE (*) (_Decimal##TYPE*)) g)(&d##TYPE); \
     d##TYPE = ((_Decimal##TYPE (*) ()) g); \
     return d##TYPE; \
   } \
   _Decimal##TYPE f2_##TYPE(_Decimal##TYPE(*)[]); \
   _Decimal##TYPE f2_##TYPE(_Decimal##TYPE(*)[3]);

#define DECIMAL_COMPOSITE_TEST(TYPE) \
do \
{ \
 _Decimal##TYPE d##TYPE; \
 d##TYPE = f1_##TYPE(g1_##TYPE); \
 d##TYPE = f1_##TYPE(g2_##TYPE); \
 d##TYPE = f2_##TYPE(h1_##TYPE); \
 d##TYPE = f2_##TYPE(h2_##TYPE); \
 d##TYPE = f2_##TYPE(h3_##TYPE); \
 (void) d##TYPE; \
} while(0)
 
DECIMAL_COMPOSITE_DECL(32);  /* { dg-error "incompatible types when assigning to type '\[^\n\]*' from type '\[^\n\]*'" } */
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } .-1 } */


DECIMAL_COMPOSITE_DECL(64);  /* { dg-error "incompatible types when assigning to type '\[^\n\]*' from type '\[^\n\]*'" } */
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } .-1 } */


DECIMAL_COMPOSITE_DECL(128); /* { dg-error "incompatible types when assigning to type '\[^\n\]*' from type '\[^\n\]*'" } */
/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } .-1 } */


int main()
{
  DECIMAL_COMPOSITE_TEST(32);  /* { dg-warning "incompatible pointer type" } */
  DECIMAL_COMPOSITE_TEST(64);  /* { dg-warning "incompatible pointer type" } */
  DECIMAL_COMPOSITE_TEST(128); /* { dg-warning "incompatible pointer type" } */

  return 0;
}