The following code compiles with GCC 4.9.2 but not with Clang 3.5.0:
#include
class Foo
{
public:
explicit operator std::string() const;
};
From [class.conv.fct]/2:
A conversion function may be explicit (7.1.2), in which case it is only considered as a user-defined conversion for direct-initialization (8.5).
So the question is how you initialize your objects. Clearly baz is direct-initialized, so this works. By contrast, bar is direct-list-initialized, but not direct-initialized, and so the explicit conversion is not available.