You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make forward parameters of concrete type accept convertible/derived arguments
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
}
Copy file name to clipboardExpand all lines: regression-tests/test-results/gcc-10-c++20/pure2-bugfix-for-requires-clause-in-forward-declaration.cpp.output
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
7
7
../../../include/cpp2util.h:10005:47: error: static assertion failed: GCC 11 or higher is required to support variables and type-scope functions that have a 'requires' clause. This includes a type-scope 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)', which relies on being able to add a 'requires' clause - in that case, use 'forward s: _' instead if you need the result to compile with GCC 10.
8
8
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
Copy file name to clipboardExpand all lines: regression-tests/test-results/gcc-10-c++20/pure2-bugfix-for-ufcs-arguments.cpp.output
+2-2
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,13 @@ pure2-bugfix-for-ufcs-arguments.cpp2:74:39: error: expected ‘;’ at end of me
6
6
In file included from pure2-bugfix-for-ufcs-arguments.cpp:7:
7
7
../../../include/cpp2util.h:10005:47: error: static assertion failed: GCC 11 or higher is required to support variables and type-scope functions that have a 'requires' clause. This includes a type-scope 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)', which relies on being able to add a 'requires' clause - in that case, use 'forward s: _' instead if you need the result to compile with GCC 10.
8
8
pure2-bugfix-for-ufcs-arguments.cpp2:75:1: note: in expansion of macro ‘CPP2_REQUIRES_’
0 commit comments