Skip to content

[BUG] Implicit move/forward interferes with main UFCS branch #888

@JohelEGP

Description

@JohelEGP

Title: Implicit move/forward interferes with main UFCS branch.

Description:

The semantics of x.f() are that
if x.f() is well-formed, it is that,
otherwise it is f(x).

When f is a local subject to implicit move/forward,
the inserted std:: call makes the main branch never be taken.

Currently, #832 prevents that from being tested.

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

t: @struct type = {
  f: (this) -> int == 2;
}
main: () = {
  {
    f := :(_) -> _ == 1;
    assert(0.f() == 1);
  }
  {
    f := :(_) -> _ == 1;
    assert(t.f() == 2);
  }
}
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: The UFCS macro to consider x.f() instead of x.std::move(f).

Actual result and error:

Output:
main.cpp2(10,5): error: local variable f is not used; consider changing its name to '_' to make it explicitly anonymous, or removing it entirely if its side effects are not needed

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions