c++ - Catch slicing
- Matthew Wilson (18/18) Aug 17 2003 Walter
- Walter (6/24) Aug 20 2003 It's not so easy to tell that a class has been derived from, such as if
- Matthew Wilson (6/39) Aug 20 2003 I appreciate that, but surely it's possible to readily deduce that a non...
- Walter (5/47) Aug 21 2003 What's a POD?
- Matthew Wilson (9/59) Aug 21 2003 Plain Old Data. Stuff with ctors/dtors/copy-assignment ops/etc.
- Matthew Wilson (3/65) Aug 21 2003 3.9
- Heinz Saathoff (7/9) Aug 22 2003 ^^^^
- Matthew Wilson (4/13) Aug 22 2003 Yes, it was a mistake.
- Walter (3/12) Aug 25 2003 Hmm. I would think that a POD type would be defined by not having a vptr...
- Heinz Saathoff (7/9) Aug 25 2003 Not only that struct but also included structs. The standard says that
- Matthew Wilson (9/18) Aug 25 2003 Maybe we could have two levels
- Philippe Mori (8/14) Aug 27 2003 IMO, the second option is enough... Even for POD type, you should catch
- Matthew Wilson (10/27) Aug 27 2003 (not
- Philippe Mori (2/4) Aug 29 2003 It is for catch clauses that pass-by-value has no reel value for me...
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 polymorphictype"{ } It'd be sweet (and would get DMC++ a special mention in Part 5, which Imaydo 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...warnWalter How hard would it be to add a (non-default, I suppose) flag (-wxs) toin:when catching by value for non-fundamental, or for non-POD, types, asclass A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for polymorphictype"{ } It'd be sweet (and would get DMC++ a special mention in Part 5, which Imaydo 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 anon-PODtype is being caught by value? "Walter" <walter digitalmars.com> wrote in message news:bi1l46$1lbs$4 digitaldaemon.com...IIt'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...warnWalter How hard would it be to add a (non-default, I suppose) flag (-wxs) toin:when catching by value for non-fundamental, or for non-POD, types, asclass A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value for polymorphictype"{ } It'd be sweet (and would get DMC++ a special mention in Part 5, whichmaydo 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...ifI appreciate that, but surely it's possible to readily deduce that anon-PODtype 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 astoclass 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)aswarnwhen catching by value for non-fundamental, or for non-POD, types,polymorphicin:class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value forwhichtype"{ } 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...ifI appreciate that, but surely it's possible to readily deduce that anon-PODtype 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 astoclass 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)aswarnwhen catching by value for non-fundamental, or for non-POD, types,polymorphicin:class A {}; class B : public A {}; try { throw B() } catch(A a) // "Warning: Catch clause type is by value forwhichtype"{ } 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...vptr.Hmm. I would think that a POD type would be defined by not having aNot 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 timeIMO, 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...(notMaybe 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 valuethenreference or ptr) For myself I'd use -wxs2 all the timeIMO, 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 willhave the slicing problem again if you throw again the exception. I don'tseemuch 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