Commit 36c5a9e
committed
Make
A `forward` parameter with a concrete type used to require an exact match, but can now accept arguments of convertible/derived types.
The previous commit's change to `@struct` requires this change, so that code like this continues to work after the previous commit:
data: @struct type = { name: std::string; city: std::string; }
x: data = ( "Henry", "Memphis" ); // ok, uses conversions
Added `@struct<noforward>` option to allow using `@struct` with GCC 10, which doesn't support `forward` parameters. And use that in cppfront's own sources, just so cppfront itself continues building under GCC10. (Someday we'll drop GCC 10 as a supported compiler, but for now it's still doing pretty well except for the won't-backport `requires`-clause bug...)
Note that allowing the generated forwarding reference to bind to arguments of derived types was also suggested by @brevzin of @jumptrading in https://wg21.link/p2481 -- thanks Barry, for the Cpp2 suggestion and for the ISO C++ 'forward' parameter proposal paper!
More examples:
Base: @polymorphic_base type = { } // a Base type
Derived: type = { this: Base; } // a Base-derived type
b: Base = ();
d: Derived = ();
s: std::string = ();
f:(forward _: Base ) = { } // forward a Base object
g:(forward _: std::string) = { } // forward a std::string object
main: () = {
f( b ); // ok, b is-a Base
f( d ); // ok, d is-a Base
f( s ); // ERROR, s is-not-a Base
g( s ); // ok, s is-a std::string
g( "xyzzy" ); // ok, "xyzzy" is-convertible-to std::string
g( b ); // ERROR, b is-not-a std::string
}forward parameters of concrete type accept convertible/derived arguments1 parent 1590ea3 commit 36c5a9e
File tree
21 files changed
+522
-537
lines changed- include
- regression-tests/test-results
- clang-12-c++20
- gcc-10-c++20
- source
21 files changed
+522
-537
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
Lines changed: 18 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| |||
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
49 | 61 | | |
50 | 62 | | |
51 | 63 | | |
| |||
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 73 | | |
86 | 74 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
0 commit comments