ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 351b414 was
ee858bf,
checked in by Peter A. Buhr <pabuhr@…>, 4 years ago
|
add 0p test for function pointers, and seperate valid from error output
|
-
Property mode set to
100644
|
File size:
2.3 KB
|
Rev | Line | |
---|
[b81fd95] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // init1.cfa -- tests of initializing pointer- and reference-typed variables and returns |
---|
| 8 | // |
---|
| 9 | // Author : Michael Brooks |
---|
| 10 | // Created On : Thu Jul 16 22:00:00 2020 |
---|
[ee858bf] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Fri Oct 9 23:11:02 2020 |
---|
| 13 | // Update Count : 5 |
---|
[b81fd95] | 14 | // |
---|
| 15 | |
---|
| 16 | void f() { |
---|
| 17 | |
---|
| 18 | // |
---|
| 19 | // setup |
---|
| 20 | // |
---|
| 21 | |
---|
| 22 | float x = 3.14; |
---|
| 23 | |
---|
| 24 | float & rx = x; |
---|
| 25 | float * px = &x; |
---|
| 26 | |
---|
| 27 | const float & crx = x; |
---|
| 28 | const float * cpx = &x; |
---|
| 29 | |
---|
| 30 | // |
---|
| 31 | // sound initializations |
---|
| 32 | // |
---|
| 33 | |
---|
| 34 | char * str1 = "hi"; |
---|
| 35 | const char * str2 = "hi"; |
---|
| 36 | |
---|
| 37 | float & rx2 = rx; |
---|
| 38 | float * px2 = px; |
---|
| 39 | |
---|
| 40 | const float & crx2 = crx; |
---|
| 41 | const float * cpx2 = cpx; |
---|
| 42 | |
---|
[ee858bf] | 43 | int (* fp)( int ) = 0p; |
---|
| 44 | fp = 0p; |
---|
| 45 | |
---|
[b81fd95] | 46 | // |
---|
| 47 | // unsound initializations |
---|
| 48 | // |
---|
| 49 | |
---|
[ee858bf] | 50 | #ifdef ERR1 |
---|
[b81fd95] | 51 | // mismatched referenced type |
---|
| 52 | int & ry = rx; |
---|
| 53 | int * py = px; |
---|
| 54 | |
---|
| 55 | // would discard refered constness (same float is referenced) |
---|
| 56 | float & ry2 = crx; |
---|
| 57 | float * py2 = cpx; |
---|
[ee858bf] | 58 | #endif // ERR1 |
---|
[b81fd95] | 59 | } |
---|
| 60 | |
---|
| 61 | // |
---|
| 62 | // sound returns |
---|
| 63 | // |
---|
| 64 | |
---|
| 65 | char * f_str1() { |
---|
| 66 | return "hi"; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | const char * f_str2() { |
---|
| 70 | return "hi"; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | float & f_rx2 () { |
---|
| 74 | float & rx = *0p; |
---|
| 75 | return rx; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | float * f_px2 () { |
---|
| 79 | float * px = 0p; |
---|
| 80 | return px; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | const float & f_crx2 () { |
---|
| 84 | float & rx = *0p; |
---|
| 85 | return rx; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | const float * f_cpx2 () { |
---|
| 89 | float * px = 0p; |
---|
| 90 | return px; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // |
---|
| 94 | // unsound returns |
---|
| 95 | // |
---|
| 96 | |
---|
[ee858bf] | 97 | #ifdef ERR1 |
---|
[b81fd95] | 98 | int & f_ry() { |
---|
| 99 | float & rx = *0p; |
---|
| 100 | return rx; // mismatched referenced type |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | int * f_py() { |
---|
| 104 | float * px = 0p; |
---|
| 105 | return px; // mismatched referenced type |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | float & f_ry2() { |
---|
| 109 | const float & crx = *0p; |
---|
| 110 | return crx; // would discard refered constness (same float is referenced) |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | float * f_py2() { |
---|
| 114 | const float * cpx = 0p; |
---|
| 115 | return cpx; // would discard refered constness (same float is referenced) |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | forall (dtype T, dtype S) |
---|
| 119 | T & anycvt( S & s ) { |
---|
| 120 | return s; // mismatched referenced type |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | forall (dtype T, dtype S) |
---|
| 124 | T * anycvt( S * s ) { |
---|
| 125 | return s; // mismatched referenced type |
---|
| 126 | } |
---|
[ee858bf] | 127 | #endif // ERR1 |
---|
| 128 | |
---|
| 129 | int main() { |
---|
| 130 | #pragma message( "Compiled" ) // force non-empty .expect file |
---|
| 131 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.