Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[BUG] No direct UFCS syntax for (captured function object, dependent base member, function object prvalue) #748

Open

Description

Title: Can't capture function object for UFCS.

Description:

As an exercise, I tried implementing the CL combinators from Function Composition in Programming Languages - Conor Hoekstra - CppNorth 2023.

Implementations

https://cpp2.godbolt.org/z/WjTTnf383:
1699742209
1697146848
1697146876

At first, I tried using UFCS.
That doesn't work because the capture is the postfix-expression before the $.
That includes the object argument.
But I just wanted the function object.

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

w: (f) :(x) x.f$();
// w: (f) :(x) f$(x);
main: () = {
  assert(w(:(x) -x;)(1) == -1);
}
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: Same as not using UFCS.

Actual result and error:

Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



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

[[nodiscard]] auto w(auto const& f) -> auto;
// w: (f) :(x) f$(x);
auto main() -> int;
  

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

[[nodiscard]] auto w(auto const& f) -> auto { return [_0 = x.f](auto const& x) -> auto { return _0();  };  }

auto main() -> int{
  cpp2::Default.expects(w([](auto const& x) -> auto { return -x;  })(1) == -1, "");
}
Output:
build/main.cpp:19:60: error: use of undeclared identifier 'x'
   19 | [[nodiscard]] auto w(auto const& f) -> auto { return [_0 = x.f](auto const& x) -> auto { return _0();  };  }
      |                                                            ^
build/main.cpp:19:97: error: use of undeclared identifier '_0'
   19 | [[nodiscard]] auto w(auto const& f) -> auto { return [_0 = x.f](auto const& x) -> auto { return _0();  };  }
      |                                                                                                 ^
build/main.cpp:19:77: warning: unused parameter 'x' [-Wunused-parameter]
   19 | [[nodiscard]] auto w(auto const& f) -> auto { return [_0 = x.f](auto const& x) -> auto { return _0();  };  }
      |                                                                             ^
build/main.cpp:19:34: warning: unused parameter 'f' [-Wunused-parameter]
   19 | [[nodiscard]] auto w(auto const& f) -> auto { return [_0 = x.f](auto const& x) -> auto { return _0();  };  }
      |                                  ^
2 warnings and 2 errors generated.

Activity

  1. ghost added
    bug
    on Oct 12, 2023
  2. ghost changed the title [-][BUG] Can't capture function object for UFCS[/-] [+][BUG] Can't use UFCS on captured function object or dependent base member[/+] on Nov 25, 2023
  3. ghost changed the title [-][BUG] Can't use UFCS on captured function object or dependent base member[/-] [+][BUG] No direct UFCS syntax for (captured function object, dependent base member, function object prvalue)[/+] on Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions