Description
Title: Consolidated feedback on enabling more argument qualifiers.
Introduction:
Currently valid:
f(move x)
f(forward x)
f(out x)
Currently invalid:
f(in x)
See https://github.com/hsutter/cppfront/wiki/Design-note:-Explicit-discard.f(inout x)
f(copy x)
Other contexts where those keywords can be valid: #456 (comment).
in
:
Personally, as a user, if I know I can use some of them, I'd expect the ability to use all of them (with maybe the exception of
in
).
-- #198 (comment) (extract)
in x
would be an useful shorthand forstd::as_const(x)
.
Althoughin
does more when applied to a parameter.
-- #198 (comment) (extract)
Possibly related: I'm using library (flecs) with API like
ecs.system<Position, const Velocity>()
And haven't found way to specify that
const
in template call to system()foo<const int>(); //error foo<in int>(); //error
-- #425 (comment) (extract)
I don't think that can work.
In a subexpression, a parameter direction operates on an expression, not a type.
cppfront
doesn't have enough semantic information forf<in int>()
to work.
-- #425 (comment) (extract)But according to this comment #425 (comment) , it works on pointers
https://cpp2.godbolt.org/z/Tx8e9KfKc
f<* const int>();
-- #456 (comment) (extract)
copy
:
copy
at call sites could be useful too. You could be saying "hey, no matter what the function signature says, take a copy of this value. I don't want you to change it and/or I don't want to accidentally change it out from under you".
-- #198 (comment) (extract)For
copy
we probably want to avoid doing an extra second copy unconditionally when we might be calling acopy
-declared parameter.
-- #198 (comment) (extract)As I understand it, the function parameter is initialized from the argument, which in this case would be a prvalue. Guaranteed copy elision should mean no extra copy. Clang and GCC seem to agree: https://compiler-explorer.com/z/Gr63qhY44.
-- #198 (comment) (extract)You can initialize a parameter from a prvalue of a non-copyable non-movable type: https://compiler-explorer.com/z/Y1x5nMT16.
So there should be no extra copy.
-- #369 (comment) (extract)An extra copy would happen if the cv unqualified type of the argument and of the (type referenced by the) parameter are different.
-- #198 (comment) (extract)
I also think copy
should subsume C++23's auto{x}
.
#408's PR allows copy x
outside an argument list, permitting this generalization.
The need for this is resolved, see #305 (comment).
Old quotes:
inout
in-particular seems like important information I'd like to see at call sites.
-- #198 (comment) (extract)For
inout
(ormut
) we probably want to know that we're calling aninout
- or possiblymove
-declared parameter. But we don't know those things unless we implement more name lookup and possibly overload resolution (neither of which cppfront has to do now) which is a big job I want to defer until later.
-- #198 (comment) (extract)
Move from last use:
Starting with #231 (68 comments).
When cppfront moves
x
on its last use it breaks the requirements of thef2
function that requires an lvalue reference but gets an rvalue reference.
-- #231 (comment) (extract)One way to suppress this could be to require a mutating argument to be qualified with
inout
, which I've thought of and @jbatez suggested in #198.
-- #231 (comment) (extract)
Then follows a very long discussion starting with #231 (comment).
It proposes to look into a way to opt-out of a function call's results,
consistent across the return value and inout
/out
arguments.
Duplicates:
- [BUG]
std::move
for last-use makes it impossible to call function withinout
parameter. #288 - [BUG] std::move(variable) in ifstream >> in the generated cpp1 code not compiling #396
Also asked at:
See also:
- [BUG] Cannot specity
<const>
or<in>
in function template arguments #456 - [BUG] Permit
operator=
within this
(via function metafunction@proxy
) #452 - [BUG] Parameter direction for template parameter is ignored #425
- [BUG] Non-
operator=
out this
function triggers assertion #421 - [BUG] Double move when passing by move #413
- [BUG] Return-by broken by "return expression list" support #408
- [BUG] Parameter named after contextual keyword is lost #397
- [BUG] No way to declare std::function that use references in cpp2 #343
- [BUG] Improve
cpp2::in
(restore old behavior, exclude problem cases only) #317 - [QUESTION] How to make of
inout
parameters of typeconst T
? #250 - [BUG] move from last use break code where variable is passed to function with
inout
argument passing #231 - Helper function to convert tokens to passing_styles. #198
- https://quuxplusone.github.io/blog/2020/07/23/grand-unified-theory-of-caller-style/.