[Bug c++/32984] add checking for array new delete

2007-08-09 Thread dcb314 at hotmail dot com


--- Comment #9 from dcb314 at hotmail dot com  2007-08-09 16:03 ---
(In reply to comment #8)
 I suggest taking a technique from the STL and using an auto_array class 

In practice, I find both STL and Boost are rarely used.
Such advanced tools are fine for experienced C++ programmers.

For ex-Fortran programmers, new to C++, making their first steps in
C++ manual memory management, the news that the C++ compiler will silently
eat certainly wrong code is worrying.

Hence my bug report. Some newbie C++ programmers need more hand-holding
than traditional C++ compilers provide.

And as C++ becomes more and more mainstream, this will be more and more
true. 

The bug report remains at resolved wontfix.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-08 Thread fang at csl dot cornell dot edu


--- Comment #8 from fang at csl dot cornell dot edu  2007-08-09 02:54 
---
Please forgive a wee bit more noise on this matter: (Yes, I know this is
resolved invalid)

If you really insist on using a pointer instead of a valarray or vector, I
suggest taking a technique from the STL and using an auto_array class template
that delete []'s an array-allocated pointer automatically upon destruction
(exception-safe too).  Overload for member operator [] to do pointer
arithmetic, for convenience.  

Taking the paradigm further, you can devise things like boost::shared_array
(TR1?), or some sort of policy-driven pointer-class that performs The
Appropriate Action (TM) upon destruction.  If you're extremist, like me, and
want to find/substitute *all* bare occurrences of operators new and delete
(outside of certified pointer/array/vector classes), 'cpp | grep' for them, no
g++ required.  :)  I can't remember the last time I botched any operation
mismatch/typo/bug/error/unbalance.  

Of course, if you didn't actually make such an error, and the example was just
a demonstration of your point, then I'm probably just preaching to the choir. 
[returns to lurking]


-- 

fang at csl dot cornell dot edu changed:

   What|Removed |Added

 CC||fang at csl dot cornell dot
   ||edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-06 Thread dcb314 at hotmail dot com


--- Comment #7 from dcb314 at hotmail dot com  2007-08-06 16:06 ---
(In reply to comment #6)
 This is one which you need huge dataflow analysis 

Doubtful. Yes/No/Don't know flag on each pointer data
member of a class would be some of it.

 and whole program to detect this problem.

I'd be happy with a one file solution to this problem, as I hope
my original problem report made clear.

In summary, my customer doesn't have HP kit, valgrind is run time 
and not compile time, the compiler isn't going to be fixed anytime soon
so I feel a Perl script may be invented.

 So closing as won't fix.

Fair enough. Point taken. I'll try a Perl script.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-05 Thread pinskia at gcc dot gnu dot org


--- Comment #6 from pinskia at gcc dot gnu dot org  2007-08-05 19:37 ---
This is not the business of a compiler to detect all and every programming
mismatch.   It can detect some but not all.  This is one which you need huge
dataflow analysis and whole program to detect this problem.

This is not going to be inside GCC for a long time and even then it will not
give good results.

So closing as won't fix.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-04 Thread gdr at cs dot tamu dot edu


--- Comment #1 from gdr at cs dot tamu dot edu  2007-08-04 13:01 ---
Subject: Re:   New: add checking for array new  delete

dcb314 at hotmail dot com [EMAIL PROTECTED] writes:

| Given the following C++ code
| 
| class K
| {
| public:
| void f();
| void g();
| 
| private:
| int * a;
| double * b;
| float * c;
| unsigned int * d;
| };
| 
| void K :: f()
| {
| a = new int;
| b = new double [ 10];
| delete c;
| delete [] d;
| }
| 
| void K :: g()
| {
| delete [] a;// error
| delete b;   // error
| c = new float [ 20];// error
| d = new unsigned int;   // error
| }
| 
| Recent snapshot g++ 4.3 20070803 can't find anything
| wrong with the code.

Special, dedicated tools exist for that task.  I would suggest
you use one of them.  

The above should not be the business of the *compiler*.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-04 Thread dcb314 at hotmail dot com


--- Comment #2 from dcb314 at hotmail dot com  2007-08-04 19:52 ---
(In reply to comment #1)
 Special, dedicated tools exist for that task.  

Would you be willing to name three of them ?

 The above should not be the business of the *compiler*.

Why not ?

The compiler can generate a whole bunch of warnings
already.

Are you suggesting these existing warnings are none
of the business of the compiler ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



Re: [Bug c++/32984] add checking for array new delete

2007-08-04 Thread Gabriel Dos Reis
dcb314 at hotmail dot com [EMAIL PROTECTED] writes:

| The compiler can generate a whole bunch of warnings
| already.

Which fall in different mindset that the one you would like.

-- Gaby


[Bug c++/32984] add checking for array new delete

2007-08-04 Thread gdr at cs dot tamu dot edu


--- Comment #3 from gdr at cs dot tamu dot edu  2007-08-04 22:06 ---
Subject: Re:  add checking for array new  delete

dcb314 at hotmail dot com [EMAIL PROTECTED] writes:

| The compiler can generate a whole bunch of warnings
| already.

Which fall in different mindset that the one you would like.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-04 Thread gdr at cs dot tamu dot edu


--- Comment #4 from gdr at cs dot tamu dot edu  2007-08-04 22:09 ---
Subject: Re:  add checking for array new  delete

dcb314 at hotmail dot com [EMAIL PROTECTED] writes:

| (In reply to comment #1)
|  Special, dedicated tools exist for that task.  
| 
| Would you be willing to name three of them ?

web searchers are your friends.  look for valgrind and friends.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984



[Bug c++/32984] add checking for array new delete

2007-08-04 Thread sebor at roguewave dot com


--- Comment #5 from sebor at roguewave dot com  2007-08-05 00:31 ---
There are third party tools that track these types of problems. Some of them
have started to make their way into compilers. For example, the HP static
analysis tool called Code Adviser is integrated into the HP aCC compiler on
IPF (see www.hp.com/go/cadvise).


-- 

sebor at roguewave dot com changed:

   What|Removed |Added

 CC||sebor at roguewave dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32984