Consider the following example:
struct ConvertibleStruct {};
enum class ConvertibleEC {};
struct Target {
// Implicit conversion constructors
Target(ConvertibleStruct) {}
Target(ConvertibleEC) {}
};
Target operator~(const Target& t) {
return t;
}
Target anotherFunction(const Target& t) {
return t;
}
int main() {
ConvertibleStruct t;
ConvertibleEC ec;
~t; // 1. Works finding the operator overloaded above
~ec; // 2. Fails to compile on clang 3.4 and gcc 4.8.2
operator~(ec); // 3. Works finding the operator overloaded above
anotherFunction(ec); // 4. Works
}
Compiler versions:
The above findings are for clang 3.4
and gcc 4.8.2
. Test 2. actually compiles fine on gcc 4.7.3
with -std=c++11
. Possibly a bug in early GCC C++11 implementation?
Assertions:
- Given that 1. compiles, user-defined implicit-conversions are checked when calling the
~
operator. - Given that 4. compiles, user-defined implicit-conversions are checked for
enum class
objects.
Questions:
- Are the above assertions correct?
- If they are, why does 2. fail to compile?
- Given that 2. fails to compile, why does 3. compile?