-
Notifications
You must be signed in to change notification settings - Fork 260
[BUG] Can't access conversion function #583
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
Comments
The intent is that all conversions are invoked using This works -- does it satisfy your use case?
|
In my case, I'm porting to Cpp2 a concept to check this (https://eel.is/c++draft/meta.rqmts#1.sentence-4):
So I need to check the existence of that |
I'd also like to declare conversion operators in Cpp2. For simplicity, Cpp2's This is what I'm envisioning:
#include "https://raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h"
struct A {
operator bool() const { return true; }
};
struct B {
template<std::same_as<bool> T> auto operator_as() const -> T { return true; }
};
struct C { };
template<std::same_as<bool> T> auto operator_as(C) -> T { return true; }
namespace cpp2 {
template<class T> auto operator_as(auto&& x) -> decltype(auto)
requires requires { CPP2_FORWARD(x).operator T(); }
|| requires { CPP2_FORWARD(x).template operator_as<T>(); }
|| requires { operator_as<T>(CPP2_FORWARD(x)); }
{
if constexpr (requires { CPP2_FORWARD(x).operator T(); }) {
return CPP2_FORWARD(x).operator T();
} else if constexpr (requires { CPP2_FORWARD(x).template operator_as<T>(); }) {
return CPP2_FORWARD(x).template operator_as<T>();
} else {
return operator_as<T>(CPP2_FORWARD(x));
}
}
}
#include <cassert>
int main() {
assert(cpp2::operator_as<bool>(A{}));
assert(cpp2::operator_as<bool>(B{}));
assert(cpp2::operator_as<bool>(C{}));
} |
Authoring an |
Title: Can't access conversion function.
Minimal reproducer (https://cpp2.godbolt.org/z/49od88YbG):
Commands:
cppfront main.cpp2 clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp
Expected result: Same as using the commented out Cpp1
main
.Actual result and error:
The text was updated successfully, but these errors were encountered: