Skip to content

[BUG] Function expression in alias has access specifier #842

Open
@JohelEGP

Description

@JohelEGP

Title: Function expression in alias has access specifier.

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

v: @struct type = {
  f: std::type_identity_t<decltype(+ :(_: int) 0)> == :(_: int) 0;
  g: (i) i.f();
}
main: () = { }
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:

  public: static const std::type_identity_t<decltype(+[]([[maybe_unused]] cpp2::in<int> unnamed_param_1) -> auto { return 0; })> f;

Actual result and error:

  public: static const std::type_identity_t<decltype(+public: []([[maybe_unused]] cpp2::in<int> unnamed_param_1) -> auto { return 0; })> f;
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"

class v;
  

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

class v {
  public: static const std::type_identity_t<decltype(+public: []([[maybe_unused]] cpp2::in<int> unnamed_param_1) -> auto { return 0; })> f;
  public: [[nodiscard]] static auto g(auto const& i) -> auto;
};
auto main() -> int;

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


  inline CPP2_CONSTEXPR std::type_identity_t<decltype(+[]([[maybe_unused]] cpp2::in<int> unnamed_param_1) -> auto { return 0; })> v::f = []([[maybe_unused]] cpp2::in<int> unnamed_param_1) -> auto { return 0; };
  [[nodiscard]] auto v::g(auto const& i) -> auto { return CPP2_UFCS_0(f, i);  }

auto main() -> int{}
Output:
main.cpp2:2:55: error: expected expression
    2 |   public: static const std::type_identity_t<decltype(+public: []([[maybe_unused]] cpp2::in<int> unnamed_param_1) -> auto { return 0; })> f;
      |                                                       ^
1 error generated.

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