|
From: Florian K. <br...@ac...> - 2009-04-01 12:02:47
|
On Wednesday 01 April 2009 2:30:54 am Roberto Diaz wrote:
>
> The fact is that for this code I am not able to see valgrind reporting any
> mistake:
>
>
> #include <iostream>
>
> class A
> {
> public:
> int a () {return 0;}
> };
>
>
> int
> main ()
> {
> A *a = new A;
> std::cerr << "a: " << a << std::endl;
> delete a;
>
> // access to deleted memory
>
> std::cerr << "rst: " << a->a () << std::endl;
> }
>
>
> If I compile this with g++ -ggdb3 -o prueba1 prueba1.cc and run it with
> valgrind:
>
[snip]
>
> I dont get mistakes.. am I missing something? shouldn't I receive an invalid
> read message or something like that?
>
The memory pointed to by "a" is not accessed.
a->a() gets converted to something like method_a_of_class_A(a)
and
int method_a_of_class_A(A *this)
{
return 0;
}
You're passing a pointer to some deallocated memory but it's not being dereferenced.
Hence no complaint.
Florian
|