Movatterモバイル変換


[0]ホーム

URL:


Issue 152 - WG21 CWG Issues
Title
explicit copy constructors
Status
tc1
Section
11.4.8.2 [class.conv.ctor]
Submitter
Steve Adamczyk

Created on1999-08-04.00:00:00 last changed277 months ago

Messages

msg518 (view)
Date: 2001-04-15.00:00:00

Proposed resolution (04/01):

  1. Change the first two sentences of12.2.2.4 [over.match.ctor] paragraph 1to

    When objects of class type are direct-initialized(9.4 [dcl.init]), or copy-initializedfrom an expression of the same or a derived class type(9.4 [dcl.init]), overloadresolution selects the constructor. For direct-initialization, thecandidate functions are all the constructors of the class of the objectbeing initialized. For copy-initialization, the candidate functions areall the converting constructors(11.4.8.2 [class.conv.ctor]) of that class.
  2. Change the first sentence of 11.4.8.2 [class.conv.ctor] paragraph 3to read:

    A non-explicit copy constructor (11.4.5.3 [class.copy.ctor]) is aconverting constructor.
msg228 (view)
Date: 2001-04-15.00:00:00

Notes from 04/01 meeting:

After the issue was accepted as a DR with the proposedresolution to change 12.2.2.4 [over.match.ctor] paragraph 1as described below, it was noticed that 11.4.8.2 [class.conv.ctor] paragraph 3states that:

A copy-constructor (11.4.5.3 [class.copy.ctor]) is a convertingconstructor.

In addition to making the proposed resolution for this issueineffectual, the wording of paragraph 3 also contradicts that ofparagraph 1:

A constructor declared without thefunction-specifierexplicit that can be called with a single parameter specifiesa conversion from the type of its first parameter to the type of itsclass. Such a constructor is called a converting constructor.

These considerations led to the addition of the second pointof the proposed resolution.

Proposed resolution (04/01):

  1. Change the first two sentences of12.2.2.4 [over.match.ctor] paragraph 1to

    When objects of class type are direct-initialized(9.5 [dcl.init]), or copy-initializedfrom an expression of the same or a derived class type(9.5 [dcl.init]), overloadresolution selects the constructor. For direct-initialization, thecandidate functions are all the constructors of the class of the objectbeing initialized. For copy-initialization, the candidate functions areall the converting constructors(11.4.8.2 [class.conv.ctor]) of that class.
  2. Change the first sentence of 11.4.8.2 [class.conv.ctor] paragraph 3to read:

    A non-explicit copy constructor (11.4.5.3 [class.copy.ctor]) is aconverting constructor.
msg149 (view)
Date: 2022-02-18.07:47:23

Can a copy-constructor declared asexplicit be used tocopy class values implicitly? For example,

   struct X {      X();      explicit X(const X&);   };   void f(X);   int main() { X x; f(x); }
According to 11.4.8.2 [class.conv.ctor]paragraphs 2-3,
An explicit constructor constructs objects just like non-explicitconstructors, but does so only where the direct-initialization syntax(9.5 [dcl.init]) or where casts(7.6.1.9 [expr.static.cast],7.6.3 [expr.cast]) are explicitly used...A copy-constructor (11.4.5.3 [class.copy.ctor]) is aconverting constructor. An implicitly-declared copy constructor isnot an explicit constructor; it may be called for implicit typeconversions.
This passage would appear to indicate that the call in the example isill-formed, since it uses neither the direct-initialization syntax noran explicit cast. The last sentences are especially interesting inthis regard, indicating thatexplicit andnon-explicit copy constructors are handled differently.

On the other hand,9.5 [dcl.init] paragraph 14, bullet 4,sub-bullet 2 says,

If the initialization is direct-initialization, or if it iscopy-initialization where the cv-unqualified version of the sourcetype is the same class as, or a derived class of, the class of thedestination... [the] applicable constructors are enumerated(12.2.2.4 [over.match.ctor])...
The cited passage says that
The candidate functions are all the constructors of the class of theobject being initialized.
History
DateUserActionArgs
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2001-05-20 00:00:00adminsetmessages: +msg518
2000-11-18 00:00:00adminsetstatus: ready -> dr
2000-05-21 00:00:00adminsetstatus: review -> ready
2000-02-23 00:00:00adminsetmessages: +msg228
2000-02-23 00:00:00adminsetstatus: open -> review
1999-08-04 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp