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] Disable UFCS on deduced return type not yet deduced (f: () x.f();) #874

Open
JohelEGP opened this issue Dec 6, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Dec 6, 2023

Title: Disable UFCS on deduced return type not yet deduced (f: () x.f();).

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

#include <ranges>
arity: @struct type = {
  range: type == std::ranges::iota_view<i16, i16>;
  value: range = ();
  begin: (this) -> _ = {
    return std::ranges::iterator_t<range>(); // Deduce.
    return value.begin(); // OK.
    return begin(); // Recurses.
  }
  // error: function 'end' with deduced return type cannot be used before it is defined
  end: (this) value.end();
}
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp

Expected result: For arity::end to be well-formed by not naming itself in its body.

Actual result and error:

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


#include "cpp2util.h"

#line 1 "/app/example.cpp2"

#line 2 "/app/example.cpp2"
class arity;
  

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

#line 1 "/app/example.cpp2"
#include <ranges>
class arity {
#line 3 "/app/example.cpp2"
  public: using range = std::ranges::iota_view<cpp2::i16,cpp2::i16>;
  public: range value {}; 
  public: [[nodiscard]] auto begin() const& -> auto;

#line 10 "/app/example.cpp2"
  // error: function 'end' with deduced return type cannot be used before it is defined
  public: [[nodiscard]] auto end() const& -> auto;
};
auto main() -> int;

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

#line 1 "/app/example.cpp2"

#line 5 "/app/example.cpp2"
  [[nodiscard]] auto arity::begin() const& -> auto{
    return std::ranges::iterator_t<range>(); // Deduce.
    return CPP2_UFCS(begin)(value); // OK.
    return begin(); // Recurses.
  }

  [[nodiscard]] auto arity::end() const& -> auto { return CPP2_UFCS(end)(value);  }

auto main() -> int{}
Output:
main.cpp2:11:69: error: function 'end' with deduced return type cannot be used before it is defined
   11 |   [[nodiscard]] auto arity::end() const& -> auto { return CPP2_UFCS(end)(value);  }
      |                                                                     ^
main.cpp2:11:29: note: 'end' declared here
   11 |   [[nodiscard]] auto arity::end() const& -> auto { return CPP2_UFCS(end)(value);  }
      |                             ^

See also:

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

1 participant