c++ - Catch slicing
- "Matthew Wilson" <matthew stlsoft.org> Aug 17 2003
- "Walter" <walter digitalmars.com> Aug 20 2003
- "Matthew Wilson" <matthew stlsoft.org> Aug 20 2003
- "Walter" <walter digitalmars.com> Aug 21 2003
- "Matthew Wilson" <dmd synesis.com.au> Aug 21 2003
- "Matthew Wilson" <dmd synesis.com.au> Aug 21 2003
- Heinz Saathoff <hsaat bre.ipnet.de> Aug 22 2003
- "Matthew Wilson" <dmd synesis.com.au> Aug 22 2003
- "Walter" <walter digitalmars.com> Aug 25 2003
- Heinz Saathoff <hsaat bre.ipnet.de> Aug 25 2003
- "Matthew Wilson" <matthew stlsoft.org> Aug 25 2003
- "Philippe Mori" <philippe_mori hotmail.com> Aug 27 2003
- "Matthew Wilson" <matthew stlsoft.org> Aug 27 2003
- "Philippe Mori" <philippe_mori hotmail.com> Aug 29 2003
Walter
How hard would it be to add a (non-default, I suppose) flag (-wxs) to warn
when catching by value for non-fundamental, or for non-POD, types, as in:
class A
{};
class B
: public A
{};
try
{
throw B()
}
catch(A a) // "Warning: Catch clause type is by value for polymorphic type"
{
}
It'd be sweet (and would get DMC++ a special mention in Part 5, which I may
do next).
Matthew
Aug 17 2003
It's not so easy to tell that a class has been derived from, such as if class B is in another file. "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bhpg7o$1sfb$1 digitaldaemon.com...Walter How hard would it be to add a (non-default, I suppose) flag (-wxs) to warn when catching by value for non-fundamental, or for non-POD, types, as in: class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for polymorphic
{ } It'd be sweet (and would get DMC++ a special mention in Part 5, which I
do next). Matthew
Aug 20 2003
I appreciate that, but surely it's possible to readily deduce that a non-POD type is being caught by value? "Walter" <walter digitalmars.com> wrote in message news:bi1l46$1lbs$4 digitaldaemon.com...It's not so easy to tell that a class has been derived from, such as if class B is in another file. "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bhpg7o$1sfb$1 digitaldaemon.com...Walter How hard would it be to add a (non-default, I suppose) flag (-wxs) to
when catching by value for non-fundamental, or for non-POD, types, as
class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for polymorphic
{ } It'd be sweet (and would get DMC++ a special mention in Part 5, which I
do next). Matthew
Aug 20 2003
What's a POD? "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bi1piu$1rrj$1 digitaldaemon.com...I appreciate that, but surely it's possible to readily deduce that a
type is being caught by value? "Walter" <walter digitalmars.com> wrote in message news:bi1l46$1lbs$4 digitaldaemon.com...It's not so easy to tell that a class has been derived from, such as if class B is in another file. "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bhpg7o$1sfb$1 digitaldaemon.com...Walter How hard would it be to add a (non-default, I suppose) flag (-wxs) to
when catching by value for non-fundamental, or for non-POD, types, as
class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for polymorphic
{ } It'd be sweet (and would get DMC++ a special mention in Part 5, which
maydo next). Matthew
Aug 21 2003
Plain Old Data. Stuff with ctors/dtors/copy-assignment ops/etc. I'm pretty sure it's defined in the standard. I'll have a look. "Walter" <walter digitalmars.com> wrote in message news:bi4cq6$2n5h$1 digitaldaemon.com...What's a POD? "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bi1piu$1rrj$1 digitaldaemon.com...I appreciate that, but surely it's possible to readily deduce that a
type is being caught by value? "Walter" <walter digitalmars.com> wrote in message news:bi1l46$1lbs$4 digitaldaemon.com...It's not so easy to tell that a class has been derived from, such as
class B is in another file. "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bhpg7o$1sfb$1 digitaldaemon.com...Walter How hard would it be to add a (non-default, I suppose) flag (-wxs)
warnwhen catching by value for non-fundamental, or for non-POD, types,
in:class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for
type"{ } It'd be sweet (and would get DMC++ a special mention in Part 5,
Imaydo next). Matthew
Aug 21 2003
3.9 "Matthew Wilson" <dmd synesis.com.au> wrote in message news:bi4cta$2n97$1 digitaldaemon.com...Plain Old Data. Stuff with ctors/dtors/copy-assignment ops/etc. I'm pretty sure it's defined in the standard. I'll have a look. "Walter" <walter digitalmars.com> wrote in message news:bi4cq6$2n5h$1 digitaldaemon.com...What's a POD? "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bi1piu$1rrj$1 digitaldaemon.com...I appreciate that, but surely it's possible to readily deduce that a
type is being caught by value? "Walter" <walter digitalmars.com> wrote in message news:bi1l46$1lbs$4 digitaldaemon.com...It's not so easy to tell that a class has been derived from, such as
class B is in another file. "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bhpg7o$1sfb$1 digitaldaemon.com...Walter How hard would it be to add a (non-default, I suppose) flag (-wxs)
warnwhen catching by value for non-fundamental, or for non-POD, types,
in:class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for
type"{ } It'd be sweet (and would get DMC++ a special mention in Part 5,
Imaydo next). Matthew
Aug 21 2003
Matthew Wilson schrieb...Plain Old Data. Stuff with ctors/dtors/copy-assignment ops/etc.
without POD structs should only consist of simple data members. No member functions at all. POD type variables can be safely copied with memcopy. - Heinz
Aug 22 2003
Yes, it was a mistake. And yes, I agree with all that you've said about POD "Heinz Saathoff" <hsaat bre.ipnet.de> wrote in message news:MPG.19afdfd9e86c795f9896ce news.digitalmars.com...Matthew Wilson schrieb...Plain Old Data. Stuff with ctors/dtors/copy-assignment ops/etc.
without POD structs should only consist of simple data members. No member functions at all. POD type variables can be safely copied with memcopy. - Heinz
Aug 22 2003
Hmm. I would think that a POD type would be defined by not having a vptr. "Heinz Saathoff" <hsaat bre.ipnet.de> wrote in message news:MPG.19afdfd9e86c795f9896ce news.digitalmars.com...Matthew Wilson schrieb...Plain Old Data. Stuff with ctors/dtors/copy-assignment ops/etc.
without POD structs should only consist of simple data members. No member functions at all. POD type variables can be safely copied with memcopy. - Heinz
Aug 25 2003
Walter schrieb...Hmm. I would think that a POD type would be defined by not having a vptr.
Not only that struct but also included structs. The standard says that PODs are classic C-structs which makes sense. This also gives compiler writes more freedom in implementing things. For DMC I know that adding members isn't a problem and I still can memcpy such structs. But it's not guaranteed by the standard. - Heinz
Aug 25 2003
Maybe we could have two levels -wxs1 - whatever meaningful definition of non-POD types being caught by value (not reference or ptr) -wxs2 - any type other than fundamental types being caught by value (not reference or ptr) For myself I'd use -wxs2 all the time "Heinz Saathoff" <hsaat bre.ipnet.de> wrote in message news:MPG.19b3f7e93fbe82389896cf news.digitalmars.com...Walter schrieb...Hmm. I would think that a POD type would be defined by not having a
Not only that struct but also included structs. The standard says that PODs are classic C-structs which makes sense. This also gives compiler writes more freedom in implementing things. For DMC I know that adding members isn't a problem and I still can memcpy such structs. But it's not guaranteed by the standard. - Heinz
Aug 25 2003
"Matthew Wilson" <matthew stlsoft.org> a écrit dans le message de news:bicnia$938$1 digitaldaemon.com...Maybe we could have two levels -wxs1 - whatever meaningful definition of non-POD types being caught by value (not reference or ptr) -wxs2 - any type other than fundamental types being caught by value (not reference or ptr) For myself I'd use -wxs2 all the time
IMO, the second option is enough... Even for POD type, you should catch them by reference as it is possible to derive from a structure and will then have the slicing problem again if you throw again the exception. I don't see much benefit in catch by value.... but then what is the difference with passing parameters to a function by value!
Aug 27 2003
"Philippe Mori" <philippe_mori hotmail.com> wrote in message news:biirgo$ida$1 digitaldaemon.com..."Matthew Wilson" <matthew stlsoft.org> a écrit dans le message de news:bicnia$938$1 digitaldaemon.com...Maybe we could have two levels -wxs1 - whatever meaningful definition of non-POD types being caught by value (not reference or ptr) -wxs2 - any type other than fundamental types being caught by value
reference or ptr) For myself I'd use -wxs2 all the time
IMO, the second option is enough... Even for POD type, you should catch them by reference as it is possible to derive from a structure and will
have the slicing problem again if you throw again the exception. I don't
much benefit in catch by value.... but then what is the difference with passing parameters to a function by value!
Well, one thing with pbv is that it is a must when used on iterators in algorithms. Overall, I agree that only the second would be of use to me, but I was just wanting to cater for sloppy programmers and hard-pressed compiler implementers
Aug 27 2003
Well, one thing with pbv is that it is a must when used on iterators in algorithms.
It is for catch clauses that pass-by-value has no reel value for me... For other cases like function parameters, it is different.
Aug 29 2003









"Matthew Wilson" <dmd synesis.com.au> 