I have found that the following code gives a compile error on gcc 4.7.3 but not on clang 3.3:
#include <cstdint>
struct X {
explicit operator uint32_t() { return 0; }
};
int main() {
static_cast< int >( X() );
return 0;
}
The question is, which is right? Gcc 4.7.3 says:
testcast.cpp:8:29: error: invalid static_cast from type 'X' to type 'int'
What I think happens is that clang uses the uint32_t operator to get an unsigned and then implicitly converts that to int. I suspect the spec does not leave this undefined, and as such I'd expect one of the compilers to be wrong.
uint32_t.Acan convert intoBwhich can convert intoC, it does NOT meanAcan directly convert intoC.