Open
Description
These codes cannot be complied with clang 19, but of no problem with MSVC and GCC.
#include <iostream>
#include <string>
#include <vector>
class A
{
std::string a;
std::vector<A> v;
public:
A(int i) { a = std::to_string(i); }
int toInt() const { return atoi(a.c_str()); }
void pushBack(const A& a) { v.push_back(a); } // line 1
template <typename T>
requires requires(const A& a, T& t) { A2T(a, t); } // line 2
operator T() const
{
T t;
A2T(*this, t);
return t;
}
};
inline void A2T(const A& a, int& f) { f = a.toInt(); }
int main()
{
A a(20);
int f = a;
std::cout << f << std::endl;
return 0;
}
The error is
<source>:43:9: error: no viable conversion from 'A' to 'int'
43 | int f = a;
| ^ ~
<source>:23:5: note: candidate template ignored: constraints not satisfied [with T = int]
23 | operator T() const
| ^
<source>:22:47: note: because 'A2T(a, t)' would be invalid: use of undeclared identifier 'A2T'
22 | requires requires(const A& a, T& t) { A2T(a, t); }
| ^
1 error generated.
But if one of the line 1 or 2 is removed, things become OK. I guess it might be a bug of concept, does anyone have other idea?