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] Implicit move on non-last use #884

Closed
JohelEGP opened this issue Dec 10, 2023 · 1 comment · Fixed by #887
Closed

[BUG] Implicit move on non-last use #884

JohelEGP opened this issue Dec 10, 2023 · 1 comment · Fixed by #887
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

Title: Implicit move on non-last use.

Minimal reproducer (https://cpp2.godbolt.org/z/z1nWesaaa):

main: () = {
  x := 0;

  if true { _ = x; }

  {
    { _ = x; }

    _ = x;
  }
}
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -Werror=unused-variable -I . main.cpp

Expected result:

    {static_cast<void>(x); }

    static_cast<void>(std::move(x));

Actual result and error:

    {static_cast<void>(std::move(x)); }

    static_cast<void>(std::move(x));
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"

#line 1 "/app/example.cpp2"


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "/app/example.cpp2"
auto main() -> int;

//=== Cpp2 function definitions =================================================

#line 1 "/app/example.cpp2"
auto main() -> int{
#line 2 "/app/example.cpp2"
  auto x {0}; 

  if (true) {static_cast<void>(x); }

  {
    {static_cast<void>(std::move(x)); }

    static_cast<void>(std::move(x));
  }
}
Output:
Program returned: 0

See also:

@JohelEGP JohelEGP added the bug Something isn't working label Dec 10, 2023
@JohelEGP
Copy link
Contributor Author

Same for the test case of #869.

v: @union @print type = {
  i: int;
}

prints

        if that.is_i()
        {
            set_i(that.i());
        }

which generates

if (CPP2_UFCS(is_i)(std::move(that))) {set_i(CPP2_UFCS(i)(std::move(that)));}

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

Successfully merging a pull request may close this issue.

1 participant