This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/51553] New: brace initialization and conversion operators


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51553

             Bug #: 51553
           Summary: brace initialization and conversion operators
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dave@boostpro.com


Please consider this test case:

--------- <schnipp> --------
struct X
{
    X();
};

struct Y
{
    operator X() const;
};

struct Z
{
    explicit operator X() const;
};

X a = { Y() };  // #1. error: could not convert '{Y()}' from '<brace-enclosed
initializer list>' to 'X'
X aa = Y();     // #1a. OK

X b{ Y() };     // #2. error: no matching function for call to
'X::X(<brace-enclosed initializer list>)'
X bb(Y());      // #2a. OK

X c = { Z() };  // #3 error: could not convert '{Z()}' from '<brace-enclosed
initializer list>' to 'X'
X cc = Z();     // #3a. error: conversion from 'Z' to non-scalar type 'X'
requested

X d{ Z() };     // #4 error: no matching function for call to
'X::X(<brace-enclosed initializer list>)'
X dd( Z() );    // OK
--------- <schnapp> --------

I can't find anything in the standard that justifies a difference between the
brace- and braceless-initialization cases.  Even in case #3, the difference in
error message leads me to think the code may be failing for the wrong reasons.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]