1  /* { dg-do compile } */
       2  /* { dg-options "-std=gnu99" } */
       3  
       4  /* C99 6.5.4 Cast operators.
       5  
       6     Test invalid casts involving fixed-point.  */
       7  
       8  #define CAST(NAME,TYPE) \
       9    struct s ## NAME { TYPE NAME; } as ## NAME; \
      10    union u ## NAME { TYPE NAME; } au ## NAME; \
      11    TYPE NAME; \
      12    TYPE * NAME ## p;
      13  
      14  CAST (sf, short _Fract)
      15  CAST (f, _Fract)
      16  CAST (lf, long _Fract)
      17  CAST (llf, long long _Fract)
      18  CAST (usf, unsigned short _Fract)
      19  CAST (uf, unsigned _Fract)
      20  CAST (ulf, unsigned long _Fract)
      21  CAST (ullf, unsigned long long _Fract)
      22  CAST (Ssf, _Sat short _Fract)
      23  CAST (Sf, _Sat _Fract)
      24  CAST (Slf, _Sat long _Fract)
      25  CAST (Sllf, _Sat long long _Fract)
      26  CAST (Susf, _Sat unsigned short _Fract)
      27  CAST (Suf, _Sat unsigned _Fract)
      28  CAST (Sulf, _Sat unsigned long _Fract)
      29  CAST (Sullf, _Sat unsigned long long _Fract)
      30  CAST (sa, short _Accum)
      31  CAST (a, _Accum)
      32  CAST (la, long _Accum)
      33  CAST (lla, long long _Accum)
      34  CAST (usa, unsigned short _Accum)
      35  CAST (ua, unsigned _Accum)
      36  CAST (ula, unsigned long _Accum)
      37  CAST (ulla, unsigned long long _Accum)
      38  CAST (Ssa, _Sat short _Accum)
      39  CAST (Sa, _Sat _Accum)
      40  CAST (Sla, _Sat long _Accum)
      41  CAST (Slla, _Sat long long _Accum)
      42  CAST (Susa, _Sat unsigned short _Accum)
      43  CAST (Sua, _Sat unsigned _Accum)
      44  CAST (Sula, _Sat unsigned long _Accum)
      45  CAST (Sulla, _Sat unsigned long long _Accum)
      46  
      47  void
      48  test (void)
      49  {
      50    (short _Fract []) sfp; /* { dg-error "cast specifies array type" } */
      51    (_Fract []) fp; /* { dg-error "cast specifies array type" } */
      52    (long _Fract []) lfp; /* { dg-error "cast specifies array type" } */
      53    (long long _Fract []) llfp; /* { dg-error "cast specifies array type" } */
      54    (unsigned short _Fract []) usfp; /* { dg-error "cast specifies array type" } */
      55    (unsigned _Fract []) ufp; /* { dg-error "cast specifies array type" } */
      56    (unsigned long _Fract []) ulfp; /* { dg-error "cast specifies array type" } */
      57    (unsigned long long _Fract []) ullfp; /* { dg-error "cast specifies array type" } */
      58    (_Sat short _Fract []) Ssfp; /* { dg-error "cast specifies array type" } */
      59    (_Sat _Fract []) Sfp; /* { dg-error "cast specifies array type" } */
      60    (_Sat long _Fract []) Slfp; /* { dg-error "cast specifies array type" } */
      61    (_Sat long long _Fract []) Sllfp; /* { dg-error "cast specifies array type" } */
      62    (_Sat unsigned short _Fract []) Susfp; /* { dg-error "cast specifies array type" } */
      63    (_Sat unsigned _Fract []) Sufp; /* { dg-error "cast specifies array type" } */
      64    (_Sat unsigned long _Fract []) Sulfp; /* { dg-error "cast specifies array type" } */
      65    (_Sat unsigned long long _Fract []) Sullfp; /* { dg-error "cast specifies array type" } */
      66    (short _Accum []) sap; /* { dg-error "cast specifies array type" } */
      67    (_Accum []) ap; /* { dg-error "cast specifies array type" } */
      68    (long _Accum []) lap; /* { dg-error "cast specifies array type" } */
      69    (long long _Accum []) llap; /* { dg-error "cast specifies array type" } */
      70    (unsigned short _Accum []) usap; /* { dg-error "cast specifies array type" } */
      71    (unsigned _Accum []) uap; /* { dg-error "cast specifies array type" } */
      72    (unsigned long _Accum []) ulap; /* { dg-error "cast specifies array type" } */
      73    (unsigned long long _Accum []) ullap; /* { dg-error "cast specifies array type" } */
      74    (_Sat short _Accum []) Ssap; /* { dg-error "cast specifies array type" } */
      75    (_Sat _Accum []) Sap; /* { dg-error "cast specifies array type" } */
      76    (_Sat long _Accum []) Slap; /* { dg-error "cast specifies array type" } */
      77    (_Sat long long _Accum []) Sllap; /* { dg-error "cast specifies array type" } */
      78    (_Sat unsigned short _Accum []) Susap; /* { dg-error "cast specifies array type" } */
      79    (_Sat unsigned _Accum []) Suap; /* { dg-error "cast specifies array type" } */
      80    (_Sat unsigned long _Accum []) Sulap; /* { dg-error "cast specifies array type" } */
      81    (_Sat unsigned long long _Accum []) Sullap; /* { dg-error "cast specifies array type" } */
      82  
      83    (short _Fract ()) sfp; /* { dg-error "cast specifies function type" } */
      84    (_Fract ()) fp; /* { dg-error "cast specifies function type" } */
      85    (long _Fract ()) lfp; /* { dg-error "cast specifies function type" } */
      86    (long long _Fract ()) llfp; /* { dg-error "cast specifies function type" } */
      87    (unsigned short _Fract ()) usfp; /* { dg-error "cast specifies function type" } */
      88    (unsigned _Fract ()) ufp; /* { dg-error "cast specifies function type" } */
      89    (unsigned long _Fract ()) ulfp; /* { dg-error "cast specifies function type" } */
      90    (unsigned long long _Fract ()) ullfp; /* { dg-error "cast specifies function type" } */
      91    (_Sat short _Fract ()) Ssfp; /* { dg-error "cast specifies function type" } */
      92    (_Sat _Fract ()) Sfp; /* { dg-error "cast specifies function type" } */
      93    (_Sat long _Fract ()) Slfp; /* { dg-error "cast specifies function type" } */
      94    (_Sat long long _Fract ()) Sllfp; /* { dg-error "cast specifies function type" } */
      95    (_Sat unsigned short _Fract ()) Susfp; /* { dg-error "cast specifies function type" } */
      96    (_Sat unsigned _Fract ()) Sufp; /* { dg-error "cast specifies function type" } */
      97    (_Sat unsigned long _Fract ()) Sulfp; /* { dg-error "cast specifies function type" } */
      98    (_Sat unsigned long long _Fract ()) Sullfp; /* { dg-error "cast specifies function type" } */
      99    (short _Accum ()) sap; /* { dg-error "cast specifies function type" } */
     100    (_Accum ()) ap; /* { dg-error "cast specifies function type" } */
     101    (long _Accum ()) lap; /* { dg-error "cast specifies function type" } */
     102    (long long _Accum ()) llap; /* { dg-error "cast specifies function type" } */
     103    (unsigned short _Accum ()) usap; /* { dg-error "cast specifies function type" } */
     104    (unsigned _Accum ()) uap; /* { dg-error "cast specifies function type" } */
     105    (unsigned long _Accum ()) ulap; /* { dg-error "cast specifies function type" } */
     106    (unsigned long long _Accum ()) ullap; /* { dg-error "cast specifies function type" } */
     107    (_Sat short _Accum ()) Ssap; /* { dg-error "cast specifies function type" } */
     108    (_Sat _Accum ()) Sap; /* { dg-error "cast specifies function type" } */
     109    (_Sat long _Accum ()) Slap; /* { dg-error "cast specifies function type" } */
     110    (_Sat long long _Accum ()) Sllap; /* { dg-error "cast specifies function type" } */
     111    (_Sat unsigned short _Accum ()) Susap; /* { dg-error "cast specifies function type" } */
     112    (_Sat unsigned _Accum ()) Suap; /* { dg-error "cast specifies function type" } */
     113    (_Sat unsigned long _Accum ()) Sulap; /* { dg-error "cast specifies function type" } */
     114    (_Sat unsigned long long _Accum ()) Sullap; /* { dg-error "cast specifies function type" } */
     115  
     116    (struct ssf) sf; /* { dg-error "conversion to non-scalar type requested" } */
     117    (struct sf) f; /* { dg-error "conversion to non-scalar type requested" } */
     118    (struct slf) lf; /* { dg-error "conversion to non-scalar type requested" } */
     119    (struct sllf) llf; /* { dg-error "conversion to non-scalar type requested" } */
     120    (struct susf) usf; /* { dg-error "conversion to non-scalar type requested" } */
     121    (struct suf) uf; /* { dg-error "conversion to non-scalar type requested" } */
     122    (struct sulf) ulf; /* { dg-error "conversion to non-scalar type requested" } */
     123    (struct sullf) ullf; /* { dg-error "conversion to non-scalar type requested" } */
     124    (struct sSsf) Ssf; /* { dg-error "conversion to non-scalar type requested" } */
     125    (struct sSf) Sf; /* { dg-error "conversion to non-scalar type requested" } */
     126    (struct sSlf) Slf; /* { dg-error "conversion to non-scalar type requested" } */
     127    (struct sSllf) Sllf; /* { dg-error "conversion to non-scalar type requested" } */
     128    (struct sSusf) Susf; /* { dg-error "conversion to non-scalar type requested" } */
     129    (struct sSuf) Suf; /* { dg-error "conversion to non-scalar type requested" } */
     130    (struct sSulf) Sulf; /* { dg-error "conversion to non-scalar type requested" } */
     131    (struct sSullf) Sullf; /* { dg-error "conversion to non-scalar type requested" } */
     132    (struct ssa) sa; /* { dg-error "conversion to non-scalar type requested" } */
     133    (struct sa) a; /* { dg-error "conversion to non-scalar type requested" } */
     134    (struct sla) la; /* { dg-error "conversion to non-scalar type requested" } */
     135    (struct slla) lla; /* { dg-error "conversion to non-scalar type requested" } */
     136    (struct susa) usa; /* { dg-error "conversion to non-scalar type requested" } */
     137    (struct sua) ua; /* { dg-error "conversion to non-scalar type requested" } */
     138    (struct sula) ula; /* { dg-error "conversion to non-scalar type requested" } */
     139    (struct sulla) ulla; /* { dg-error "conversion to non-scalar type requested" } */
     140    (struct sSsa) Ssa; /* { dg-error "conversion to non-scalar type requested" } */
     141    (struct sSa) Sa; /* { dg-error "conversion to non-scalar type requested" } */
     142    (struct sSla) Sla; /* { dg-error "conversion to non-scalar type requested" } */
     143    (struct sSlla) Slla; /* { dg-error "conversion to non-scalar type requested" } */
     144    (struct sSusa) Susa; /* { dg-error "conversion to non-scalar type requested" } */
     145    (struct sSua) Sua; /* { dg-error "conversion to non-scalar type requested" } */
     146    (struct sSula) Sula; /* { dg-error "conversion to non-scalar type requested" } */
     147    (struct sSulla) Sulla; /* { dg-error "conversion to non-scalar type requested" } */
     148  
     149    (union usf) sf;
     150    (union uf) f;
     151    (union ulf) lf;
     152    (union ullf) llf;
     153    (union uusf) usf;
     154    (union uuf) uf;
     155    (union uulf) ulf;
     156    (union uullf) ullf;
     157    (union uSsf) Ssf;
     158    (union uSf) Sf;
     159    (union uSlf) Slf;
     160    (union uSllf) Sllf;
     161    (union uSusf) Susf;
     162    (union uSuf) Suf;
     163    (union uSulf) Sulf;
     164    (union uSullf) Sullf;
     165    (union usa) sa;
     166    (union ua) a;
     167    (union ula) la;
     168    (union ulla) lla;
     169    (union uusa) usa;
     170    (union uua) ua;
     171    (union uula) ula;
     172    (union uulla) ulla;
     173    (union uSsa) Ssa;
     174    (union uSa) Sa;
     175    (union uSla) Sla;
     176    (union uSlla) Slla;
     177    (union uSusa) Susa;
     178    (union uSua) Sua;
     179    (union uSula) Sula;
     180    (union uSulla) Sulla;
     181  
     182    (union usf) f; /* { dg-error "cast to union type from type not present in union" } */
     183    (union usf) lf; /* { dg-error "cast to union type from type not present in union" } */
     184    (union usf) llf; /* { dg-error "cast to union type from type not present in union" } */
     185    (union usf) usf; /* { dg-error "cast to union type from type not present in union" } */
     186    (union usf) uf; /* { dg-error "cast to union type from type not present in union" } */
     187    (union usf) ulf; /* { dg-error "cast to union type from type not present in union" } */
     188    (union usf) ullf; /* { dg-error "cast to union type from type not present in union" } */
     189    (union usf) Ssf; /* { dg-error "cast to union type from type not present in union" } */
     190    (union usf) Sf; /* { dg-error "cast to union type from type not present in union" } */
     191    (union usf) Slf; /* { dg-error "cast to union type from type not present in union" } */
     192    (union usf) Sllf; /* { dg-error "cast to union type from type not present in union" } */
     193    (union usf) Susf; /* { dg-error "cast to union type from type not present in union" } */
     194    (union usf) Suf; /* { dg-error "cast to union type from type not present in union" } */
     195    (union usf) Sulf; /* { dg-error "cast to union type from type not present in union" } */
     196    (union usf) Sullf; /* { dg-error "cast to union type from type not present in union" } */
     197    (union usf) sa; /* { dg-error "cast to union type from type not present in union" } */
     198    (union usf) a; /* { dg-error "cast to union type from type not present in union" } */
     199    (union usf) la; /* { dg-error "cast to union type from type not present in union" } */
     200    (union usf) lla; /* { dg-error "cast to union type from type not present in union" } */
     201    (union usf) usa; /* { dg-error "cast to union type from type not present in union" } */
     202    (union usf) ua; /* { dg-error "cast to union type from type not present in union" } */
     203    (union usf) ula; /* { dg-error "cast to union type from type not present in union" } */
     204    (union usf) ulla; /* { dg-error "cast to union type from type not present in union" } */
     205    (union usf) Ssa; /* { dg-error "cast to union type from type not present in union" } */
     206    (union usf) Sa; /* { dg-error "cast to union type from type not present in union" } */
     207    (union usf) Sla; /* { dg-error "cast to union type from type not present in union" } */
     208    (union usf) Slla; /* { dg-error "cast to union type from type not present in union" } */
     209    (union usf) Susa; /* { dg-error "cast to union type from type not present in union" } */
     210    (union usf) Sua; /* { dg-error "cast to union type from type not present in union" } */
     211    (union usf) Sula; /* { dg-error "cast to union type from type not present in union" } */
     212    (union usf) Sulla; /* { dg-error "cast to union type from type not present in union" } */
     213  
     214    (short _Fract) assf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     215    (_Fract) asf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     216    (long _Fract) aslf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     217    (long long _Fract) asllf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     218    (unsigned short _Fract) asusf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     219    (unsigned _Fract) asuf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     220    (unsigned long _Fract) asulf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     221    (unsigned long long _Fract) asullf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     222    (_Sat short _Fract) asSsf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     223    (_Sat _Fract) asSf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     224    (_Sat long _Fract) asSlf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     225    (_Sat long long _Fract) asSllf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     226    (_Sat unsigned short _Fract) asSusf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     227    (_Sat unsigned _Fract) asSuf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     228    (_Sat unsigned long _Fract) asSulf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     229    (_Sat unsigned long long _Fract) asSullf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     230    (short _Accum) assa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     231    (_Accum) asa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     232    (long _Accum) asla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     233    (long long _Accum) aslla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     234    (unsigned short _Accum) asusa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     235    (unsigned _Accum) asua; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     236    (unsigned long _Accum) asula; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     237    (unsigned long long _Accum) asulla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     238    (_Sat short _Accum) asSsa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     239    (_Sat _Accum) asSa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     240    (_Sat long _Accum) asSla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     241    (_Sat long long _Accum) asSlla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     242    (_Sat unsigned short _Accum) asSusa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     243    (_Sat unsigned _Accum) asSua; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     244    (_Sat unsigned long _Accum) asSula; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     245    (_Sat unsigned long long _Accum) asSulla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     246  
     247    (short _Fract) ausf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     248    (_Fract) auf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     249    (long _Fract) aulf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     250    (long long _Fract) aullf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     251    (unsigned short _Fract) auusf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     252    (unsigned _Fract) auuf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     253    (unsigned long _Fract) auulf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     254    (unsigned long long _Fract) auullf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     255    (_Sat short _Fract) auSsf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     256    (_Sat _Fract) auSf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     257    (_Sat long _Fract) auSlf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     258    (_Sat long long _Fract) auSllf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     259    (_Sat unsigned short _Fract) auSusf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     260    (_Sat unsigned _Fract) auSuf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     261    (_Sat unsigned long _Fract) auSulf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     262    (_Sat unsigned long long _Fract) auSullf; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     263    (short _Accum) ausa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     264    (_Accum) aua; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     265    (long _Accum) aula; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     266    (long long _Accum) aulla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     267    (unsigned short _Accum) auusa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     268    (unsigned _Accum) auua; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     269    (unsigned long _Accum) auula; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     270    (unsigned long long _Accum) auulla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     271    (_Sat short _Accum) auSsa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     272    (_Sat _Accum) auSa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     273    (_Sat long _Accum) auSla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     274    (_Sat long long _Accum) auSlla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     275    (_Sat unsigned short _Accum) auSusa; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     276    (_Sat unsigned _Accum) auSua; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     277    (_Sat unsigned long _Accum) auSula; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     278    (_Sat unsigned long long _Accum) auSulla; /* { dg-error "aggregate value used where a fixed-point was expected" } */
     279  }