-
Notifications
You must be signed in to change notification settings - Fork 260
[BUG] _parameter-direction_ can't pass const address of fundamental type #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm very curious about what Herb has to say about this. I still think current behaviour is fine and the following should be enough to address this situation:
Now, I'm very sure that this will not suffice, but it works for the |
That's right.
The second point would help #686. |
Sorry, but I don't understand the example of pushing onto a vector. Can you please explain. |
I'm trying to grok the question. Two key points:
The intent was that this would be implemented using
This compiles and runs successfully, which seems right. Does that help? I'm reading quickly here, so sorry if I missed something. Thanks for the feedback! |
That works in this case (https://cpp2.godbolt.org/z/66e76d8K8). I see some drawbacks in the general case:
So I think my suggested |
And |
OK, those are reasonable concerns. For a while I wondered whether we'd have demand for an always-copy parameter, and it turns out we do, so I added So the question is "are there use cases when you know you want to guarantee aliasing?" Normally for a feature extension I'd say "I want to be driven by use cases, and But in this case I think there's a short cut, because this isn't actually a feature extension, or at least not as much: The I think this will be a worthwhile experiment! Thanks for persisting on this, I appreciate it. |
(Note the first commit mentioned immediately above says it closed this issue, but that was a stray commit comment. The second one immediately following it is the one that closed this.) Thanks! |
From #666, another use case:
|
Title: parameter-direction can't pass const address of fundamental type.
Description:
Cpp2
in
parameters don't guarantee aliasing their corresponding argument,or something like that (e.g., the guarantee to not alias is implementation-defined).
This is my best guess, as there's no public documentation for Cpp2.
#686 argues that this should be less observable for the cases
in
parameters alias.The other side of the coin is that
you can't pass a
const
object to a Cpp2 parameter and be guaranteed aliasing.I'm going to beat the dead horse with the usual example
because I can't currently come up with an use case where I need this.
But I do have a suggestion that, while it borders on clever (or is, for you), might just work.
This issue means that you can't translate Cpp1 function signatures like the following one
to Cpp2 with just parameter-directions
without having to resort to type traits such as
std::add_lvalue_reference_t<const int>
.That's a concrete version of
std::min
.The following would work in this case (https://cpp2.godbolt.org/z/38WEGK8vr):
So this occured to me:
Of course, there was some resistance (as there always is when suggesting complicating parameter directions).
Like using pointers, which I might, were I writing a new interface.
But this issue will definitely come up when translating Cpp1 to Cpp2.
Minimal reproducer (https://cpp2.godbolt.org/z/jW71x6sv6):
Commands:
cppfront main.cpp2 clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp
Expected result:
Program returned: 0
.Also, as pointed out by #686, similar behavior whether the chosen parameter type aliases or not.
And considering #666, I'm against actually making
in
parameters always alias.As pointed out in the description,
I'd expect this result if
inout _: const _
was enabledto mean something like "
in
parameter with guaranteed aliasing".Actual result and error:
Cpp2 lowered to Cpp1:
The text was updated successfully, but these errors were encountered: