public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63999] New: Explcit conversion operators are not considered for explicit cast using brace
@ 2014-11-20 16:14 tomaszkam at gmail dot com
  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
  0 siblings, 2 replies; 3+ messages in thread
From: tomaszkam at gmail dot com @ 2014-11-20 16:14 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/63999] Explcit conversion operators are not considered for explicit cast using brace
  2014-11-20 16:14 [Bug c++/63999] New: Explcit conversion operators are not considered for explicit cast using brace tomaszkam at gmail dot com
@ 2014-11-20 16:16 ` 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
  1 sibling, 0 replies; 3+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-11-20 16:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63999

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-20
                 CC|                            |ville.voutilainen at gmail dot com
     Ever confirmed|0                           |1

--- Comment #1 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
Same result if all the bools are changed to ints. clang accepts the code.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/63999] Explicit conversion operators are not considered for explicit cast using braces
  2014-11-20 16:14 [Bug c++/63999] New: Explcit conversion operators are not considered for explicit cast using brace tomaszkam at gmail dot com
  2014-11-20 16:16 ` [Bug c++/63999] " ville.voutilainen at gmail dot com
@ 2021-08-09 21:40 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-09 21:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63999

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 67631.

*** This bug has been marked as a duplicate of bug 67631 ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-09 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-20 16:14 [Bug c++/63999] New: Explcit conversion operators are not considered for explicit cast using brace tomaszkam at gmail dot com
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

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).