You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <cstdio>
#include <utility>
struct A { operator int&(); };
int& ir = A();
int main()
{
return 0;
}
This block of code will be transformed to
#include <cstdio>
#include <utility>
struct A
{
operator int & ();
};
int & ir = static_cast<int>(A().operator int &());
int main()
{
return 0;
}
which can not be compiled correctly, because the return value of static_cast<int> is a rvalue and c++ standard does not allowed that non-const lvalue reference of type'int' binds to a rvalue of type int.
According to the standard, it should use the conversion function turnsA() into a int& type.
thanks for raising that issue! It looks like showing ImplicitCastExpr for CastKind::CK_UserDefinedConversion isn't helpful because this introduces the invalid cast to int instead of int&. C++ Insights will no longer show that implicit cast, which makes the transformation correct and shorter in various cases.
This block of code will be transformed to
which can not be compiled correctly, because the return value of
static_cast<int>
is a rvalue and c++ standard does not allowed that non-const lvalue reference of type'int' binds to a rvalue of type int.According to the standard, it should use the conversion function turns
A()
into aint&
type.Here is the link of this term in a html version of cpp working paper.
https://timsong-cpp.github.io/cppwp/n4868/dcl.init.ref#5.2
The text was updated successfully, but these errors were encountered: