From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25078 invoked by alias); 20 Nov 2014 16:14:06 -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 25033 invoked by uid 48); 20 Nov 2014 16:14:03 -0000 From: "tomaszkam at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/63999] New: Explcit conversion operators are not considered for explicit cast using brace Date: Thu, 20 Nov 2014 16:14: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: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tomaszkam 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-11/txt/msg02274.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63999 Bug ID: 63999 Summary: Explcit conversion operators are not considered for explicit cast using brace Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tomaszkam at gmail dot com For the following code: struct bool_convert { explicit operator bool() { return true; } }; bool x(bool_convert()); //1 bool x1{bool_convert{}}; //2 bool x2 = bool{bool_convert{}}; //3 Both line 1 and 2 compiles correcty, while the line 3 produces following error: error: cannot convert 'bool_convert' to 'bool' in initialization. According to the standard section $5.2.3 [expr.type.conv]/3: Similarly, a simple-type-specifier or typename-specifier followed by a braced-init-list creates a temporary object of the specified type direct-list-initialized (8.5.4) with the specified braced-init-list, and its value is that temporary object as a prvalue. That means that cast notation from the line 3 should have equivalent semantics to the one from line 2. Section $12.3.2 [class.conv.fct]/2: A conversion function may be explicit (7.1.2), in which case it is only considered as a user-defined conversion for direct-initialization (8.5). Otherwise, user-defined conversions are not restricted to use in assignments and initializations. Explicit conversion operator should be invoked for direct initialization so behaviour for line 3 is incoorect and conversion operator should be used.