Changeset d2034b4 for src/tests


Ignore:
Timestamp:
Mar 19, 2018, 5:29:23 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
f810e09
Parents:
c5ce0ec (diff), 12db9e4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

Location:
src/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/tests/.expect/references.txt

    rc5ce0ec rd2034b4  
    2828Destructing a Y
    2929Destructing a Y
     303 3
     313
     323
     333 9 { 1, 7 }, [1, 2, 3]
    3034Destructing a Y
    3135Destructing a Y
  • src/tests/references.c

    rc5ce0ec rd2034b4  
    4949                &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    5050        ***p3 = 3;                          // change x
     51        // ((int&)r3 = 3;                      // change x, ***r3
    5152        **p3 = &x;                          // change p1
     53        // ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    5254        *p3 = &p1;                          // change p2
     55        // ((int**&)&&r3) = &p2;               // change r2, (&(&*)*)*r3
     56        // ((int***&)&&&r3) = p3;              // change r3 to p3, (&(&(&*)*)*)r3
    5357        int y = 0, z = 11, & ar[3] = { x, y, z };    // initialize array of references
     58        // &ar[1] = &z;                        // change reference array element
     59        // typeof( ar[1] ) p;                  // is int, i.e., the type of referenced object
     60        // typeof( &ar[1] ) q;                 // is int &, i.e., the type of reference
     61        // sizeof( ar[1] ) == sizeof( int );   // is true, i.e., the size of referenced object
     62        // sizeof( &ar[1] ) == sizeof( int *); // is true, i.e., the size of a reference
    5463
    5564        // test that basic reference properties are true - r1 should be an alias for x
     
    7685        &z1.r = &z1r;
    7786        &z2.r = &z2r;
     87
    7888        z1 = z2;
     89
     90        // test rvalue-to-reference conversion
     91        {
     92                struct S { double x, y; };
     93                void f( int & i, int & j, S & s, int v[] ) {
     94                        printf("%d %d { %g, %g }, [%d, %d, %d]\n", i, j, s.[x, y], v[0], v[1], v[2]);
     95                }
     96                void g(int & i) { printf("%d\n", i); }
     97                void h(int &&& i) { printf("%d\n", i); }
     98
     99                int &&& r = 3;  // rvalue to reference
     100                int i = r;
     101                printf("%d %d\n", i, r);  // both 3
     102
     103                g( 3 );          // rvalue to reference
     104                h( (int &&&)3 ); // rvalue to reference
     105
     106                int a = 5, b = 4;
     107                f( 3, a + b, (S){ 1.0, 7.0 }, (int [3]){ 1, 2, 3 } ); // two rvalue to reference
     108        }
    79109}
    80110
Note: See TracChangeset for help on using the changeset viewer.