Skip to content

Heisenbug when compiling f(move auto a, in auto b) invoked with f(move(s), s) #16

Description

@hsutter

The basic case is:

void move_in(move auto a, in auto b) { copy_from(a, b); }
// ...
move_in(std::move(s), s);

This bug seems fragile... each of the following repros sometimes crashes the compiler, sometimes fails compilation without crashing, and sometimes succeeds:

Just keep hitting Godbolt's "clear cache and recompile" button, and the answer for each changes from run to run of the compiler.

Original report: https://www.reddit.com/r/cpp/comments/j8tf9k/empirically_measuring_reducing_cs_accidental/g8zfd9x/

Note that with the Lifetime rules we'd get a warning that the two arguments alias. Still, even without that diagnostic we should not crash, but still translate the well-formed program with the semantics that the last use of parameter a (the copy_from(a,b) call) moves from a, and because b is passed by pointer (so will alias a in this code) and the evaluation of a and b are not indeterminately sequenced then the evaluation of b should copy either the original or moved-from state of the object.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions