File tree Expand file tree Collapse file tree 2 files changed +32
-12
lines changed Expand file tree Collapse file tree 2 files changed +32
-12
lines changed Original file line number Diff line number Diff line change 4
4
rm -f * o constplay * ~ constplay.sol
5
5
6
6
constplay : constplay.cpp
7
- ${CXX} -Wall -Wextra -L. -o $@ $<
7
+ ${CXX} -std=c++17 - Wall -Wextra -L. -o $@ $<
Original file line number Diff line number Diff line change 7
7
*/
8
8
void copy (int a) {
9
9
[[maybe_unused]] int val = a;
10
- };
10
+ }
11
11
12
12
void copyConst (const int a) {
13
13
[[maybe_unused]] int val = a;
14
- };
14
+ }
15
15
16
16
void write (int * a) {
17
17
*a = 42 ;
18
- };
18
+ }
19
+ void write (int & a) {
20
+ a = 42 ;
21
+ }
19
22
20
- void read (const int * a) {
23
+ void read (const int * a) {
21
24
[[maybe_unused]] int val = *a;
22
- };
25
+ }
26
+ void read (int const & a) {
27
+ [[maybe_unused]] int val = a = 2 ;
28
+ }
23
29
24
30
struct Test {
25
31
void hello (std::string &s) {
@@ -56,12 +62,24 @@ int main() {
56
62
copyConst (m);
57
63
58
64
// try constant arguments of functions with pointers
59
- int *p = 0 ;
60
- const int *r = 0 ;
61
- write (p);
62
- write (r);
63
- read (p);
64
- read (r);
65
+ {
66
+ int *p = 0 ;
67
+ const int *r = 0 ;
68
+ write (p);
69
+ write (r);
70
+ read (p);
71
+ read (r);
72
+ }
73
+
74
+ // try constant arguments of functions with references
75
+ {
76
+ int p = 0 ;
77
+ const int r = 0 ;
78
+ write (2 );
79
+ write (r);
80
+ read (2 );
81
+ read (r);
82
+ }
65
83
66
84
// try constant method in a class
67
85
Test t;
@@ -71,4 +89,6 @@ int main() {
71
89
tc.hello (s);
72
90
t.helloConst (s);
73
91
tc.helloConst (s);
92
+
93
+ return 0 ;
74
94
}
You can’t perform that action at this time.
0 commit comments