Article View: comp.std.c++
Article #3938Re: Must exception classes have copy constructors?
From: Steve Clamage
Date: Sat, 06 Apr 1996 19:35
Date: Sat, 06 Apr 1996 19:35
30 lines
2111 bytes
2111 bytes
Alan Griffiths <aGriffiths@ma.ccngroup.com> writes:
>I've just tried porting some code to MSVC4 (it compiles and works with
>SC7.1 and BC4.5).
>In effect it appears that the Microsoft compiler _requires_ anything
>thrown as an exception to have an accessible copy constructor. (I've
>tended to make copy constructors private to ensure catch-by-reference
>and aviod slicing bugs.)
According to the draft standard, when you throw something, what is
thrown is actually a copy of that something. If the copy constructor
for that something is not accessible, the copy can't be made.
Under some circumstances the copy can be optimized away. The draft
standard was recently clarified to say that when logically a copy
is needed, the copy constructor must be accessible even if in a
particular case a compiler happens to optimize away the copy.
In your case, you will probably have to throw a pointer instead
of a value, if the type has a private copy constructor.
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<4k6130$l22@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<606373375wnr@ma.ccngroup.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Must exception classes have copy constructors? Date: 06 Apr 1996 11:35:46 PST Organization: Sun Microsystems Inc., Mountain View, CA Approved: austern@isolde.mti.sgi.com Message-ID: <4k6130$l22@engnews1.Eng.Sun.COM> References: <606373375wnr@ma.ccngroup.com> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 6 Apr 1996 15:02:56 GMT X-Newsreader: NN version 6.5.0 #21 (NOV) X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMWbHkky4NqrwXLNJAQHVtgH/Z4+hvCau+oTdn9LTiQYRoqd3a2WaoxpV AibiY3q9X4Jg/nP8orD/LBsZ67S9aXx3N2Hh8BeTOZuLiEUpn7AuAw== =6uYg Originator: austern@isolde.mti.sgi.com