From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8280 invoked by alias); 12 Aug 2014 19:27:01 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 8258 invoked by uid 48); 12 Aug 2014 19:26:56 -0000 From: "yaghmour.shafik at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/62110] New: Attempting to use template conversion operator in a contextual conversion Date: Tue, 12 Aug 2014 19:27:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yaghmour.shafik at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg00791.txt.bz2 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 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 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