Skip to content
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

[BUG] inout parameter without non-const use of x works #230

Closed
filipsajdak opened this issue Jan 17, 2023 · 2 comments
Closed

[BUG] inout parameter without non-const use of x works #230

filipsajdak opened this issue Jan 17, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@filipsajdak
Copy link
Contributor

In section 1.3.2 inout parameters of https://github.com/hsutter/708/blob/main/708.pdf you specify that

If the function is nonvirtual, at least one path must contain a non-const use of x (else the parameter should be in).

In the current implementation of cppfront the following code compiles:

f2: (inout x) -> _ = {
    return x * 2;
}

main: () -> int = {
    x := 21;
    std::cout << f2(x) << std::endl;
    x = 0; // workaround for another bug
}

And generate output:

42

Expectations

cppfront should end with an error informing to use in argument passing instead of inout.

@filipsajdak filipsajdak added the bug Something isn't working label Jan 17, 2023
@hsutter
Copy link
Owner

hsutter commented Jan 17, 2023

Right, I'm not able to detect that right now so it's not possible to issue that diagnostic.

I could probably do this if I required a mutating argument to be qualified with inout, which I've thought of and @jbatez suggested in #198.

I see there's a related issue in #231 which might also be solved with an inout argument (call-site) requirement...

@filipsajdak
Copy link
Contributor Author

I found that issue while playing with for..do loops.

I assume that there is no call-site there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants