Warning on C++ catch by value on non primitive types

2005-10-12 Thread Thomas Costa
I posted this on the gcc-help list but I haven't received any replies  
so I thought that might mean that I hadn't missed anything obvious  
and gcc doesn't have such a warning at present.

Is this correct?
What are the chances of adding such a warning?
Is it basic enough to add to the 3.4.x and/or 4.x C++ front end that  
I could help with the task?




From: Thomas Costa <[EMAIL PROTECTED]>
Date: 10 October 2005 3:34:46 PM PDT
To: [EMAIL PROTECTED]
Subject: Warning on C++ catch by value on non primitive types


Is there any way to get gcc/g++ to warn on C++ code that does a  
catch by value of non primitive types (i.e. types that aren't int,  
float, bool, etc.)?


I would take a warning on any catch by value but the ideal would be  
a warning that doesn't fire for "catch (const int x)"


This continually creeps into our our C++ code base.







Re: Warning on C++ catch by value on non primitive types

2005-10-13 Thread Thomas Costa

On 13 Oct 2005, at 7:41 AM, Benjamin Kosnik wrote:




yeah, if it were in one of those books it could be added to the - 
weff-c+

+ option. It doesn't seem sensible to add a different option for an
alternative (set of?) coding rule(s).



FYI this is item 13 in MEC++.



It is on just about any decent modern C++ coding guide/list somewhere.

I think this would be a good error to have. My suggestion is to  
file an

enhancement request in gcc bugzilla, with this code:

#include 

void
foo()
{
  try
{
}
  catch (std::logic_error e)
{
}
}


saying that with -Weffc++, you want a warning. Include a link back to
this thread, so that who-ever works on this can read the initial
reaction and the suggestion by Nathan to hook into  
finish_handler_parms.




Yes, thanks for all the feedback.
I will look at the code mentioned earlier.


In the near past, Giovanni has done a good job of enhancing the More
Effective C++ rules. If you ask nicely, maybe he'd do the same for  
this.




That would be great and I will ask very, very nicely and offer to  
help any way I can however...
I didn't want this totally tied to -Weffc++ unless there was also a  
separate switch for turning it on/off because:


1.) Last time I checked g++'s own standard library headers did not  
pass -Weffc++ cleanly and hence I couldn't get a clean build of my C+ 
+ code using -Weffc++.
2.) A lot of other 3rd party C++ headers including the last version  
of Boost I was using (admittedly a relatively old version, maybe  
version 1.30) didn't pass -Weffc++ cleanly.
3.) People have many times debated the validity/usefulness of some of  
the warnings that -Weffc++ produces and I think it's better to have  
individual switches for each warning in -Weffc++ and then -Weffc++  
just becomes a batch switch that turns on the individual switches en  
masse.




best,
benjamin





Re: Warning on C++ catch by value on non primitive types

2005-10-13 Thread Thomas Costa
So can the existing set of warnings that -Weffc++ enables be broken  
up into fine grained warnings quite easily?

Has it already been done?

On 13 Oct 2005, at 11:44 AM, Mike Stump wrote:


On Oct 13, 2005, at 8:57 AM, Thomas Costa wrote:

I didn't want this totally tied to -Weffc++ unless there was also  
a separate switch for turning it on/off because:




We support fine grained warnings now.  So, this isn't a problem.   
Just be sure to mention you want a fine grained flag, and that you  
like spelling "-W..." (after you review the way we spell options).