public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tomaszkam at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-63999-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2014-11-20 16:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 16:14 tomaszkam at gmail dot com [this message]
2014-11-20 16:16 ` [Bug c++/63999] " ville.voutilainen at gmail dot com
2021-08-09 21:40 ` [Bug c++/63999] Explicit conversion operators are not considered for explicit cast using braces pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-63999-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).