The following class seems to compile, but the conversion operators are never called:
class A
{
public:
operator A() const { std::cout << "A() called" << std::endl; return *this; }
operator A&() { std::cout << "A&() called" << std::endl; return *this; }
operator const A&() const { std::cout << "const A&() called" << std::endl; return *this; }
};
Is a function specifying a conversion to a reference to itself simply ignored?
Here’s a quote from 12.3.2
A conversion function is never used to convert a (possibly cv-qualified) object to the (possibly cv-qualified) same object type (or a reference to it)Also, using
-Wall -Wextra -pedantic -ansion gcc gave me:warning: this statement has no effectfor the static cast. (Also, try clang online it will give you some nice compiler error messages).