Title
CV-qualifiers and type conversions
Status
cd1
Section
9.4 [dcl.init]
Submitter
Josee Lajoie

Created on 1998-10-24.00:00:00 last changed 189 months ago

Messages

Date: 2001-04-15.00:00:00

[Moved to DR at 4/01 meeting.]

Date: 2001-04-15.00:00:00

Proposed Resolution (04/01):

In 9.4 [dcl.init], paragraph 14, bullet 4, sub-bullet 3, change

if the function is a constructor, the call initializes a temporary of the destination type.

to

if the function is a constructor, the call initializes a temporary of the cv-unqualified version of the destination type.
Date: 2000-10-15.00:00:00

Notes from 10/00 meeting:

The original example does not illustrate the remaining problem. The following example does:

    struct C { };
    C c;
    struct A {
        A(const A&);
        A(const C&);
    };
    const volatile A a = c;    // Okay
Date: 2004-09-10.00:00:00

The description of copy-initialization in 9.4 [dcl.init] paragraph 14 says:

  • If the destination type is a (possibly cv-qualified) class type:
     ...
  • Otherwise (i.e. for the remaining copy-initialization cases), user-defined conversion sequences that can convert from the source type to the destination type or (when a conversion function is used) to a derived class thereof are enumerated ... if the function is a constructor, the call initializes a temporary of the destination type. ...
Should "destination type" in this last bullet refer to "cv-unqualified destination type" to make it clear that the destination type excludes any cv-qualifiers? This would make it clearer that the following example is well-formed:
     struct A {
       A(A&);
     };
     struct B : A { };

     struct C {
       operator B&();
     };

     C c;
     const A a = c; // allowed?

The temporary created with the conversion function is an lvalue of type B. If the temporary must have the cv-qualifiers of the destination type (i.e. const) then the copy-constructor for A cannot be called to create the object of type A from the lvalue of type const B. If the temporary has the cv-qualifiers of the result type of the conversion function, then the copy-constructor for A can be called to create the object of type A from the lvalue of type const B. This last outcome seems more appropriate.

Steve Adamczyk:

Because of late changes to this area, the relevant text is now the third sub-bullet of the fourth bullet of 9.4 [dcl.init] paragraph 14:

Otherwise (i.e., for the remaining copy-initialization cases), user-defined conversion sequences that can convert from the source type to the destination type or (when a conversion function is used) to a derived class thereof are enumerated... The function selected is called with the initializer expression as its argument; if the function is a constructor, the call initializes a temporary of the destination type. The result of the call (which is the temporary for the constructor case) is then used to direct-initialize, according to the rules above, the object that is the destination of the copy-initialization.

The issue still remains whether the wording should refer to "the cv-unqualified version of the destination type." I think it should.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2003-04-25 00:00:00adminsetstatus: dr -> wp
2002-05-10 00:00:00adminsetmessages: + msg673
2001-05-20 00:00:00adminsetstatus: ready -> dr
2000-11-18 00:00:00adminsetmessages: + msg398
2000-11-18 00:00:00adminsetmessages: + msg397
2000-11-18 00:00:00adminsetstatus: drafting -> ready
1998-10-24 00:00:00admincreate