Steps: g++ -Wall ternary-ambiguous-no-error.cpp Expected behavior: I believe that the program below is ill-formed, because both implicit conversions MyString <--> const char* are possible. G++ should issue an error (or at least a warning).
>From [5.16/3]: Using this process, it is determined whether the second operand can be converted to match the third operand, and whether the third operand can be converted to match the second operand. If both can be converted, or one can be converted but the conversion is ambiguous, the program is ill-formed. Actual behavior: G++ doesn't report that. It chooses one of two ambiguous conversions and compiles cleanly. Used version: gcc version 4.0.1 (Apple Computer, Inc. build 5363) #include <string> #include <iostream> class MyString { public: MyString(const char* s) { m_s = s; } operator const char*() const { return "surprise"; } std::ostream &operator<<(std::ostream &os) { return os << m_s; } private: std::string m_s; }; int main(int argc, char* argv[]) { bool isEmpty = false; MyString s0("OK"); MyString s1 = (isEmpty) ? "" : s0; /* s1 is "surprise"; expected compile error here, because both implicit conversions MyString <--> const char* are possible. */ std::cout << s1 << std::endl; return 0; } -- Summary: Ill-formed program compiles without error. Ternary (expr.cond) operands, ambiguous conversion. Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: test dot 007 at seznam dot cz GCC build triplet: i686-apple-darwin8 GCC host triplet: i686-apple-darwin8 GCC target triplet: i686-apple-darwin8 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33314