Changeset 2e0bb92 for tests


Ignore:
Timestamp:
Jan 28, 2025, 10:10:47 PM (2 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
c699602
Parents:
c3d0182a
Message:

remove warnings, and change I/O to work with gcc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tests/designations.cfa

    rc3d0182a r2e0bb92  
    1010// Created On       : Thu Jun 29 15:26:36 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct 13 11:53:16 2024
    13 // Update Count     : 31
    14 //
    15 
    16 #include <fstream.hfa>
     12// Last Modified On : Tue Jan 28 21:49:50 2025
     13// Update Count     : 82
     14//
    1715
    1816// Note: this test case has been crafted so that it compiles with both cfa and with gcc without any modifications.
     17#include <stdio.h>
    1918#ifdef __cforall
    2019#define AT @
     
    2322#endif
    2423
     24#pragma GCC diagnostic ignored "-Wmissing-braces"
     25#pragma GCC diagnostic ignored "-Woverride-init"
     26#pragma GCC diagnostic ignored "-Wunused-variable"
     27#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
     28
     29
    2530const int indentAmt = 2;
    2631void indent( int level ) {
    27         sout | wd( level, "" ) | nonl;
     32        printf( "%*s", level, "" );
    2833}
    2934
     
    3540void printA( struct A a, int level ) {
    3641        indent( level );
    37         sout | "(A){ " | a.x | a.y | a.ptr | " }";
     42        printf( "(A){ %d %d %p }\n", a.x, a.y, a.ptr );
    3843}
    3944
     
    4449void printB( struct B b, int level ) {
    4550        indent( level );
    46         sout | "(B){";
     51        printf( "(B){\n" );
    4752        printA( b.a0, level+indentAmt );
    4853        printA( b.a1, level+indentAmt );
    4954        indent( level );
    50         sout | "}";
     55        printf( "}\n" );
    5156}
    5257
     
    5863void printC( struct C c, int level ) {
    5964        indent( level );
    60         sout | "(C){";
     65        printf( "(C){\n" );
    6166        indent( level+indentAmt );
    62         sout | "(int[]{ " | c.arr[0] | c.arr[1] | c.arr[2] | " }";
     67        printf( "(int[]{ %d %d %d }\n", c.arr[0], c.arr[1], c.arr[2] );
    6368        printB( c.b, level+indentAmt );
    6469        indent( level );
    65         sout | "}";
     70        printf( "}\n" );
    6671}
    6772
     
    7479void printD( struct D d, int level ) {
    7580        indent( level);
    76         sout | "(D){ " | d.x | "}";
     81        printf( "(D){ %d }\n", d.x );
    7782}
    7883
     
    96101        } m;
    97102};
    98 struct Fred s1 AT= { .m.j = 3 };
     103struct Fred s1 AT= { .m.j = { 3 } };
    99104struct Fred s2 AT= { .i = { [2] = 2 } };
    100105
     
    124129#endif
    125130
    126         sout | "=====A=====";
     131        printf( "=====A=====\n" );
    127132        printA( y0, 0 );
    128133        printA( y1, 0 );
    129134        printA( y2, 0 );
    130         sout | "=====A=====" | nl | nl;
     135        printf( "=====A=====\n\n" );
    131136
    132137        // initialize only first element (z0.a.x), leaving everything else default-initialized (zero), no nested curly-braces
     
    167172        };
    168173
    169         sout | "=====B=====";
     174        printf( "=====B=====\n" );
    170175        printB( z0, 0 );
    171176        printB( z1, 0 );
     
    174179        printB( z5, 0 );
    175180        printB( z6, 0 );
    176         sout | "=====B=====" | nl | nl;
     181        printf( "=====B=====\n\n" );
    177182
    178183        // TODO: what about extra things in a nested init? are empty structs skipped??
     
    185190        };
    186191
    187         sout | "=====C=====";
     192        printf( "=====C=====\n" );
    188193        printC( c1, 0 );
    189         sout | "=====C=====" | nl | nl;
     194        printf( "=====C=====\n\n" );
    190195
    191196#if ERROR
     
    211216        // array designation
    212217        int i[2] = { [1] = 3 };
     218
    213219        // allowed to have 'too many' initialized lists - essentially they are ignored.
    214220        int i1 = { 3 };
     
    241247        };
    242248
    243         sout | "=====E=====";
     249        printf( "=====E=====\n" );
    244250        printA( e0.a, 0 );
    245251        printA( e1.a, 0 );
    246252        printA( e2.a, 0 );
    247253        printB( e3.b, 0 );
    248         sout | "=====E=====" | nl | nl;
     254        printf( "=====E=====\n\n" );
    249255
    250256        // special case of initialization: char[] can be initialized with a string literal
     
    254260        const char c3[] = { 'a', 'b', 'c' };
    255261        const char c4[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} };
     262        const char ch = c4[0][0];
    256263
    257264        // more cases
     
    263270        union foo { int i; double d; };
    264271        union foo f = { .d = 4 };
    265         int v1, v2, v4;
     272        int v1 = 0, v2 = 0, v4 = 0;
    266273        int w[6] = { [1] = v1, v2, [4] = v4 };
    267274        int whitespace[256] = { [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
Note: See TracChangeset for help on using the changeset viewer.