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

Move constructors should not be POD #20617

Open
WalterBright opened this issue Dec 29, 2024 · 0 comments
Open

Move constructors should not be POD #20617

WalterBright opened this issue Dec 29, 2024 · 0 comments

Comments

@WalterBright
Copy link
Member

struct A
{
            int arr;
            this(A rhs) // move constructor not called
            {
                printf("this(A)\n");
                arr = rhs.arr;
                rhs.arr = 0;
            }
}

void main()
{
    A a;
    a.arr = 1;

    A b = __rvalue(a); // move constructor should get called
    b.arr += 1;
    assert(a.arr == 0);
    assert(b.arr == 2);
}

Adding in a copy constructor or destructor causes it to pass, because then it is non-POD and the move constructor gets passed.

See also #20616

WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 30, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 31, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Dec 31, 2024
WalterBright added a commit to WalterBright/dmd that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant