Skip to content

[BUG] [Clang] UFCS on identifier also declared at type scope fails #555

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

Open
JohelEGP opened this issue Jul 20, 2023 · 3 comments
Open

[BUG] [Clang] UFCS on identifier also declared at type scope fails #555

JohelEGP opened this issue Jul 20, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

Title: [Clang] UFCS on shared identifier between types in non-this member function.

Description:

The type of this and the unrelated type share f.
In a non-this member function,
UFCS on f with the unrelated type breaks Clang.
GCC and MSVC work, so it may be a Clang bug: https://compiler-explorer.com/z/vEEovohd3.

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

t: type = {
  f: (this) = { }
}
u: type = {
  f: (this) = { }
  g: (inout self: u) = {
    a: t = ();
    a.f();
  }
}
main: () = { }
Commands:
cppfront main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp

Expected result: A working program.

Actual result and error:

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


#include "cpp2util.h"

class t;
  

class u;
  

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

class t {
  public: auto f() const -> void;

  public: t() = default;
  public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
  public: auto operator=(t const&) -> void = delete;
};
class u {
  public: auto f() const -> void;
  public: static auto g(u& self) -> void;
    
  public: u() = default;
  public: u(u const&) = delete; /* No 'that' constructor, suppress copy */
  public: auto operator=(u const&) -> void = delete;


};
auto main() -> int;


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


  auto t::f() const -> void{}

  auto u::f() const -> void{}
  auto u::g(u& self) -> void{
    t a {}; 
    CPP2_UFCS_0(f, std::move(a));
  }

auto main() -> int{}
Output:
main.cpp2:8:17: error: call to non-static member function without an object argument
    8 |     CPP2_UFCS_0(f, std::move(a));
      |                 ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:727:16: note: expanded from macro 'CPP2_UFCS_0'
  727 |         return FUNCNAME(CPP2_FORWARD(obj)); \
      |                ^~~~~~~~
1 error generated.
@JohelEGP JohelEGP added the bug Something isn't working label Jul 20, 2023
@JohelEGP
Copy link
Contributor Author

May be related to llvm/llvm-project#58872.

@JohelEGP
Copy link
Contributor Author

You don't actually need to involve other types (https://cpp2.godbolt.org/z/qo6PErbYq, https://compiler-explorer.com/z/EeMsaj1ca):

t: @struct type = {
  f: (this) = { }
  g: (x) = x.f();
}
main: () = { }
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"

class t;
  

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

class t {
  public: auto f() const -> void;
  public: static auto g(auto const& x) -> void;
};
auto main() -> int;


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


  auto t::f() const -> void{}
  auto t::g(auto const& x) -> void { CPP2_UFCS_0(f, x);  }

auto main() -> int{}
main.cpp2:3:50: error: call to non-static member function without an object argument
    3 |   auto t::g(auto const& x) -> void { CPP2_UFCS_0(f, x);  }
      |                                                  ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:701:16: note: expanded from macro 'CPP2_UFCS_0'
  701 |         return FUNCNAME(CPP2_FORWARD(obj)); \
      |                ^~~~~~~~
1 error generated.

@JohelEGP JohelEGP changed the title [BUG] [Clang] UFCS on shared identifier between types in non-this member function [BUG] [Clang] UFCS on identifier also declared at type scope fails Aug 24, 2023
@JakeShirley
Copy link

Hitting this with Apple Clang 14.0

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

No branches or pull requests

2 participants