Skip to content

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

Description

@JohelEGP

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) { \
      |  ^
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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions