Skip to content

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

Open

Description

@JohelEGP

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.

Activity

  1. JohelEGP commented on Jul 21, 2023

    @JohelEGP
    ContributorAuthor

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

  2. JohelEGP commented on Aug 24, 2023

    @JohelEGP
    ContributorAuthor

    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.
    
  3. 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[/+] on Aug 24, 2023
  4. JakeShirley commented on Dec 3, 2023

    @JakeShirley

    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

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