Topic: explicit and a possible defect report
Author: gennaro_prota@my-deja.com
Date: Sun, 11 Feb 2001 01:16:25 GMT Raw View
Clause 12.3.1 of the standard provides the following rules/definitions:
1. A constructor declared without the function-specifier explicit that
can be called with a single parameter specifies a conversion from
the type of its first parameter to the type of its class. Such a
constructor is called a converting constructor.
3. A copy-constructor (12.8) is a converting constructor. An implicitly-
declared copy constructor is not an explicit constructor; it may be
called for implicit type conversions.
This leads to a contradiction: a copy-constructor is never an explicit
constructor, so it is (shall be?) never declared with the specifier
explicit (but from the other sentences, this doesn't seem to be the
intent).
So, in my humble opionion, that sentence should be changed to:
A copy-constructor "DECLARED WITHOUT THE FUNCTION-SPECIFIER explicit"
is a converting constructor.
Anyhow, this is implicit in 12.3.1 - 1)
Am I right?
Gennaro Prota.
Sent via Deja.com
http://www.deja.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Sun, 11 Feb 2001 14:30:44 GMT Raw View
In article <963s3l$9kt$1@nnrp1.deja.com>, gennaro_prota@my-deja.com
writes
>3. A copy-constructor (12.8) is a converting constructor. An implicitly-
> declared copy constructor is not an explicit constructor; it may be
> called for implicit type conversions.
The problem is poor language. That implicitly-declared copy constructor
actually refers to the compiler generated version, except that the
compiler generates the definition, and the writer wanted to specifically
talk about the declaration (the implicit one that is there if I do not
write one explicitly, whether or not I qualify my declaration as
explicit :)
>
>
>This leads to a contradiction: a copy-constructor is never an explicit
>constructor, so it is (shall be?) never declared with the specifier
>explicit (but from the other sentences, this doesn't seem to be the
>intent).
>
>So, in my humble opionion, that sentence should be changed to:
>
>A copy-constructor "DECLARED WITHOUT THE FUNCTION-SPECIFIER explicit"
>is a converting constructor.
>Anyhow, this is implicit in 12.3.1 - 1)
>
>
>Am I right?
--
Francis Glassborow
See http://www.accu.org for details of The ACCU Spring Conference, 2001
(includes many regular participants to C & C++ newsgroups)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: gennaro_prota@my-deja.com
Date: Sun, 11 Feb 2001 15:09:40 CST Raw View
On Sun, 11 Feb 2001 14:30:44 GMT, Francis Glassborow
<francis.glassborow@ntlworld.com> wrote:
>In article <963s3l$9kt$1@nnrp1.deja.com>, gennaro_prota@my-deja.com
>writes
>>3. A copy-constructor (12.8) is a converting constructor. An
implicitly-
>> declared copy constructor is not an explicit constructor; it may be
>> called for implicit type conversions.
>
>The problem is poor language. That implicitly-declared copy constructor
>actually refers to the compiler generated version, except that the
>compiler generates the definition, and the writer wanted to
specifically
>talk about the declaration (the implicit one that is there if I do not
>write one explicitly, whether or not I qualify my declaration as
>explicit :)
Yes, maybe I use poor language too, but it was clear to me that
implictly-declared stood for 'implementation-declared' (clause 12).
:-)))
There's no contraddiction about compiler-declared copy constructors
because clause 12.8 specifies that they are declared WITHOUT the
function-specifier explicit, so they ARE converting constructors
(12.3.1).
What puzzles me is that user-declared copy constructors MAY have the
specifier explicit so it is wrong to simply say:
"A copy-constructor (12.8) is a converting constructor." (clause 12.3.1)
I think that sentence should be either changed to
"A copy-constructor declared without the function-specifier explicit is
a converting constructor"
or removed since, after the modification, what it says is already
implicit in 12.3.1, bullet 1.
What do you think about it?
Gennaro Prota.
Sent via Deja.com
http://www.deja.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: wmm@fastdial.net
Date: Mon, 12 Feb 2001 08:44:33 CST Raw View
In article <966kp0$b1m$1@nnrp1.deja.com>,
gennaro_prota@my-deja.com wrote:
> What puzzles me is that user-declared copy constructors MAY have the
> specifier explicit so it is wrong to simply say:
>
> "A copy-constructor (12.8) is a converting constructor." (clause
12.3.1)
>
> I think that sentence should be either changed to
>
> "A copy-constructor declared without the function-specifier explicit
is
> a converting constructor"
>
> or removed since, after the modification, what it says is already
> implicit in 12.3.1, bullet 1.
>
> What do you think about it?
I think you are right, and I will open an issue in the core
language issues list to deal with it. (See
http://www.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#152
on a related topic.)
--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)
Sent via Deja.com
http://www.deja.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Mon, 12 Feb 2001 19:10:21 GMT Raw View
In article <966kp0$b1m$1@nnrp1.deja.com>, gennaro_prota@my-deja.com
writes
>Yes, maybe I use poor language too, but it was clear to me that
>implictly-declared stood for 'implementation-declared' (clause 12).
>:-)))
>
>There's no contraddiction about compiler-declared copy constructors
>because clause 12.8 specifies that they are declared WITHOUT the
>function-specifier explicit, so they ARE converting constructors
>(12.3.1).
>
>What puzzles me is that user-declared copy constructors MAY have the
>specifier explicit so it is wrong to simply say:
>
>"A copy-constructor (12.8) is a converting constructor." (clause 12.3.1)
>
>I think that sentence should be either changed to
>
>"A copy-constructor declared without the function-specifier explicit is
>a converting constructor"
>
>or removed since, after the modification, what it says is already
>implicit in 12.3.1, bullet 1.
>
>What do you think about it?
I think you are right, I think it is probably the result of editing in
the rules about explicit a little carelessly.
--
Francis Glassborow
See http://www.accu.org for details of The ACCU Spring Conference, 2001
(includes many regular participants to C & C++ newsgroups)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: joerg.barfurth@attglobal.net (Joerg Barfurth)
Date: Mon, 12 Feb 2001 22:37:13 GMT Raw View
Francis Glassborow <francis.glassborow@ntlworld.com> wrote:
> In article <963s3l$9kt$1@nnrp1.deja.com>, gennaro_prota@my-deja.com
> writes
> >3. A copy-constructor (12.8) is a converting constructor. An implicitl=
y-
> > declared copy constructor is not an explicit constructor; it may be
> > called for implicit type conversions.
>=20
> The problem is poor language. That implicitly-declared copy constructor
> actually refers to the compiler generated version, except that the
> compiler generates the definition, and the writer wanted to specificall=
y
> talk about the declaration (the implicit one that is there if I do not
> write one explicitly, whether or not I qualify my declaration as
> explicit :)
While the language may be poor, this doesn't really address the main
point:
> >This leads to a contradiction: a copy-constructor is never an explicit
> >constructor, so it is (shall be?) never declared with the specifier
> >explicit=20
IOW:
>From 12.3.1/1: A constructor is a converting constructor iif it is
declared without the keyword 'explicit' (and can be called with one
argument).
>From 12.3.1/3: A copy-constructor is a converting constructor.=20
[x] Thus we can infer that it shall not be declared using 'explicit'.
Now lets continue the argument (as I understand it):
The remainder of 12.3.1/3 seems to indicate that user-declared
copy-constuctors might be explicit constructors, in which case it may
not "be called for implicit type conversions."
> > (but from the other sentences, this doesn't seem to be the intent).
Furthermore, iirc, there is no indication in 12.8 that copy-constructors
may not be explicit. This at least suggests that it should be legal.
>From other responses I gather that knowledgeable people in this NG
indeed believe that explicit copy constructors are legal, and that they
have different semantics from non-explicit copy-constructors.
This belief is in contradiction to statement [x]. So the standard is
either misleading or even contradictory. The latter case surely warrants
a DR, in the former a clarifying statement from the comittee would still
be needed.
BTW: Personally I'm a little unsure how 'explicit' on a copy-constructor
interacts with the rules for copy-initialization, so I'd generally avoid
it.=20
Regards, J=F6rg
--=20
J=F6rg Barfurth joerg.barfurth@attglobal.net
<<<<<<<<<<<<< using std::disclaimer; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
Software Developer http://www.OpenOffice.org
StarOffice Configuration http://www.sun.com/staroffice
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: wmm@fastdial.net
Date: Tue, 13 Feb 2001 15:19:41 GMT Raw View
In article <1eool6p.f7xchr1vsiu2oN%joerg.barfurth@attglobal.net>, Joerg
Barfurth <joerg.barfurth@attglobal.net> writes:
>>From 12.3.1/1: A constructor is a converting constructor iif it is
>declared without the keyword 'explicit' (and can be called with one
>argument).
>
>>From 12.3.1/3: A copy-constructor is a converting constructor.=20
>
>[x] Thus we can infer that it shall not be declared using 'explicit'.
>
>Now lets continue the argument (as I understand it):
>
>The remainder of 12.3.1/3 seems to indicate that user-declared
>copy-constuctors might be explicit constructors, in which case it may
>not "be called for implicit type conversions."
>
>> > (but from the other sentences, this doesn't seem to be the intent).
>
>Furthermore, iirc, there is no indication in 12.8 that copy-constructors
>may not be explicit. This at least suggests that it should be legal.
>
>>From other responses I gather that knowledgeable people in this NG
>indeed believe that explicit copy constructors are legal, and that they
>have different semantics from non-explicit copy-constructors.
In the current wording of the Standard, the "explicit" qualifier on a
copy constructor has no effect. The reason is that 8.5p14 treats
"copy-initialization where the cv-unqualified version of the source type
is the same class as, or a derived class of, the class of the destination"
in the same way as direct-initialization, and 13.3.1.3p1 says that all
constructors of the class, not just the converting constructors, are
candidate functions in this case.
After some discussion, the Committee's core language working group
decided that there is some utility in being able to suppress implicit
copying by declaring the copy constructor to be "explicit" and the
Committee voted to include the proposed resolution found in
http://www.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#152 to be
in the upcoming Technical Corrigendum.
That resolution, however, depends on the idea that only non-explicit
copy constructors are "converting" constructors, in contradiction to
the statement under discussion here. It remains to be seen whether
that can be fixed editorially as part of the TC or whether we will
need a separate issue and Defect Report to change it.
>This belief is in contradiction to statement [x]. So the standard is
>either misleading or even contradictory. The latter case surely warrants
>a DR, in the former a clarifying statement from the comittee would still
>be needed.
>
>BTW: Personally I'm a little unsure how 'explicit' on a copy-constructor
>interacts with the rules for copy-initialization, so I'd generally avoid
>it.=20
Especially since the Standard is about to change on that point.
-- William M. Miller
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: celtschk@Physik.TU-Muenchen.DE (Christopher Eltschka)
Date: Wed, 14 Feb 2001 17:06:13 GMT Raw View
joerg.barfurth@attglobal.net (Joerg Barfurth) writes:
[...]
>Now lets continue the argument (as I understand it):
>The remainder of 12.3.1/3 seems to indicate that user-declared
>copy-constuctors might be explicit constructors, in which case it may
>not "be called for implicit type conversions."
Hmmm... could an explicit copy constructor prevent slicing?
class A
{
public:
explicit A(A const&);
virtual ~A();
};
class B: public A {};
void f(A);
int main()
{
A a;
B b;
f(a); // allowed (?)
f(b); // implicit conversion -> error?
}
[...]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: Thu, 15 Feb 2001 00:28:48 GMT Raw View
On Wed, 14 Feb 2001 17:06:13 GMT, celtschk@Physik.TU-Muenchen.DE
(Christopher Eltschka) wrote:
> Hmmm... could an explicit copy constructor prevent slicing?
Yes and no.
> class A
> {
> public:
> explicit A(A const&);
> virtual ~A();
> };
>
> class B: public A {};
>
> void f(A);
This function is unusable because pass by value involves copy
initialization and there is no conversion constructor available.
(See CWG issue #152)
> int main()
> {
> A a;
> B b;
>
> f(a); // allowed (?)
No. The list of constructors is empty for this copy initialization.
> f(b); // implicit conversion -> error?
Yes.
A c(b); // valid slice
A d = b; // error
> }
John
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]