source: tests/init1.cfa@ ee858bf

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since ee858bf was ee858bf, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

add 0p test for function pointers, and seperate valid from error output

  • Property mode set to 100644
File size: 2.3 KB
Line 
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
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Oct 9 23:11:02 2020
13// Update Count : 5
14//
15
16void 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
43 int (* fp)( int ) = 0p;
44 fp = 0p;
45
46 //
47 // unsound initializations
48 //
49
50 #ifdef ERR1
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;
58 #endif // ERR1
59}
60
61//
62// sound returns
63//
64
65char * f_str1() {
66 return "hi";
67}
68
69const char * f_str2() {
70 return "hi";
71}
72
73float & f_rx2 () {
74 float & rx = *0p;
75 return rx;
76}
77
78float * f_px2 () {
79 float * px = 0p;
80 return px;
81}
82
83const float & f_crx2 () {
84 float & rx = *0p;
85 return rx;
86}
87
88const float * f_cpx2 () {
89 float * px = 0p;
90 return px;
91}
92
93//
94// unsound returns
95//
96
97#ifdef ERR1
98int & f_ry() {
99 float & rx = *0p;
100 return rx; // mismatched referenced type
101}
102
103int * f_py() {
104 float * px = 0p;
105 return px; // mismatched referenced type
106}
107
108float & f_ry2() {
109 const float & crx = *0p;
110 return crx; // would discard refered constness (same float is referenced)
111}
112
113float * f_py2() {
114 const float * cpx = 0p;
115 return cpx; // would discard refered constness (same float is referenced)
116}
117
118forall (dtype T, dtype S)
119T & anycvt( S & s ) {
120 return s; // mismatched referenced type
121}
122
123forall (dtype T, dtype S)
124T * anycvt( S * s ) {
125 return s; // mismatched referenced type
126}
127#endif // ERR1
128
129int main() {
130 #pragma message( "Compiled" ) // force non-empty .expect file
131}
Note: See TracBrowser for help on using the repository browser.