https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62110
Bug ID: 62110 Summary: Attempting to use template conversion operator in a contextual conversion Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: yaghmour.shafik at gmail dot com Given the following code: class Var { public: operator int () const { return 0; } template <typename T> operator T () const { return T(); } }; int main() { Var v; switch (v) { } } gcc 4.9 produces the following error: main.cpp: In function 'int main()': main.cpp:17:14: error: default type conversion can't deduce template argument for 'template<class T> Var::operator T() const' switch (v) ^ using the following command line options: -std=c++11 -Wall -Wextra -Wconversion -pedantic Using -std=c++1y also produces the same error. while clang 3.4 does not produce any errors. As far as I can tell clang is correct here for C++1y and is probably correct for C++11 although that may depend on whether you consider N3323: "A Proposal to Tweak Certain C++ Contextual Conversions" to be a fix for C++11 or part of C++1y. N3323 is incorporated in N3485 which I consider to be C++11 with fixes but perhaps that is an incorrect interpretation. Based on this assumption then if we look at section 6.4.2 it says: The condition shall be of integral type, enumeration type, or class type. If of class type, the condition is contextually implicitly converted (Clause 4) to an integral or enumeration type. and this would force us to use section 4 paragraph 5 which does not allow or overload resolution making int conversion the only one available for this context. If N3323 is not part of C++11 then it seems unclear to me whether the template conversion function should be considered or not. This bug report comes the following Stackoverflow question: http://stackoverflow.com/questions/25047109/classes-with-both-template-and-non-template-conversion-operators-in-the-conditio