Add three memoryleak tests involving pointer casting that currently 'fail'

This commit is contained in:
Nicolas Le Cam 2008-12-13 11:19:09 +00:00
parent 46205bde8e
commit 13bcb66c14
1 changed files with 35 additions and 0 deletions

View File

@ -134,6 +134,10 @@ private:
TEST_CASE( assign );
// TODO TEST_CASE( varid );
// TODO TEST_CASE( cast1 );
// TODO TEST_CASE( cast2 ); // Doesn't fail but for bad reasons
// TODO TEST_CASE( cast3 );
}
@ -1089,6 +1093,37 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() );
}
void cast1()
{
check( "void foo()\n"
"{\n"
" char *a = reinterpret_cast<char *>(malloc(10));\n"
"}\n" );
ASSERT_EQUALS( std::string("[test.cpp:4]: Memory leak: a\n"), errout.str() );
}
void cast2()
{
check( "void foo()\n"
"{\n"
" char *a = malloc(10);\n"
" free((void *)a);\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void cast3()
{
check( "void foo()\n"
"{\n"
" char *a = malloc(10);\n"
" free(reinterpret_cast<void *>(c));\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
};
REGISTER_TEST( TestMemleak )