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] Wrong UFCS macro used outside declaration's initializer #496

Closed
JohelEGP opened this issue Jun 6, 2023 · 0 comments · Fixed by #506
Closed

[BUG] Wrong UFCS macro used outside declaration's initializer #496

JohelEGP opened this issue Jun 6, 2023 · 0 comments · Fixed by #506
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Jun 6, 2023

Title: Wrong UFCS macro used outside declaration's initializer.

Description:

See 827ed79#diff-e683e1259bbc0d6de7f1fbf797fb772f31a0a1ef2254ec317d15c298102fa3f3R2762-R2767.

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

struct A {
  constexpr bool a() { return true; }
};
f: <T> (x: std::type_identity_t<decltype(T().a())>)
  -> std::type_identity_t<decltype(T().a())>
  requires T().a() = {
  return x;
}
main: () = f<A>(true);

Commands:
cppfront -clean-cpp1 main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp

Expected result:

template<typename T> [[nodiscard]] auto f(cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_0_NONLOCAL(a, T()))>> x) -> 
  std::type_identity_t<decltype(CPP2_UFCS_0_NONLOCAL(a, T()))>
requires (CPP2_UFCS_0_NONLOCAL(a, T()))

Actual result and error:

template<typename T> [[nodiscard]] auto f(cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>> x) -> 
  std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>
requires (CPP2_UFCS_0(a, T()))
Cpp2 lowered to Cpp1:
#include "cpp2util.h"


struct A {
  constexpr bool a() { return true; }
};
template<typename T> [[nodiscard]] auto f(cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>> x) -> 
  std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>; 

auto main() -> int;

template<typename T> [[nodiscard]] auto f(cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>> x) -> 
  std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>
requires (CPP2_UFCS_0(a, T()))
  {
  std::ignore = x;
}
auto main() -> int { f<A>(true);  }
Output:
build/_cppfront/main.cpp:14:82: error: non-local lambda expression cannot have a capture-default
   14 | template<typename T> [[nodiscard]] auto f(cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>> x) -> 
      |                                                                                  ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:706:2: note: expanded from macro 'CPP2_UFCS_0'
  706 | [&](auto&& obj) CPP2_FORCE_INLINE_LAMBDA -> decltype(auto) { \
      |  ^
build/_cppfront/main.cpp:15:33: error: non-local lambda expression cannot have a capture-default
   15 |   std::type_identity_t<decltype(CPP2_UFCS_0(a, T()))>
      |                                 ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:706:2: note: expanded from macro 'CPP2_UFCS_0'
  706 | [&](auto&& obj) CPP2_FORCE_INLINE_LAMBDA -> decltype(auto) { \
      |  ^
build/_cppfront/main.cpp:16:11: error: non-local lambda expression cannot have a capture-default
   16 | requires (CPP2_UFCS_0(a, T()))
      |           ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:706:2: note: expanded from macro 'CPP2_UFCS_0'
  706 | [&](auto&& obj) CPP2_FORCE_INLINE_LAMBDA -> decltype(auto) { \
      |  ^
@JohelEGP JohelEGP added the bug Something isn't working label Jun 6, 2023
JohelEGP referenced this issue Jun 6, 2023
The `[&]` introducer is required for the UFCS lambda in case it's invoked in a deeply nested context, but then the `[&]` is illegal when it's outside a function (initializing a namespace scope object)
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