|
Boost Users : |
From: Daniel Krügler (dsp_at_[hidden])
Date: 2008-08-13 09:32:31
Olav Kindt wrote:
> Hi all,
>
>
>
> I have searched through some of the previous postings on this list, but
> have not been able to find the solution so Ill try here.
>
>
>
>
>
> I have a test case that (due to an error of course) tries to run code
> like this:
>
>
>
> class MyObject
>
> {
>
> public:
>
> virtual void f() {};
>
> };
>
>
>
> void MyFailingTestCase()
>
> {
>
> MyObject * a = NULL;
>
> a->f();
>
> }
>
>
>
> When running these tests in release mode the whole process is stopped
> by a windows dialog letting be know that there was a system error
> (Access Violation) and asks the user to click OK/Debug.
>
>
>
> I have also tried to pass the -catch_system_errors=yes, but that did
> not help
>
> I am running 1_33_1 version of the library.
> (libboost_unit_test_framework-vc80-mt-1_33_1.lib)
>
>
>
> Does anybody know a way around this problem?
The only reasonable solution is to fix the test. According
to standard C++ the expression "a->f()" using an a with
a null pointer value causes undefined behaviour.
Why don't you use a valid argument? Possible examples are:
void MyFailingTestCase()
{
MyObject mo;
MyObject* a = &mo;
a->f();
}
or
void MyFailingTestCase()
{
MyObject a;
a.f();
}
or
void MyFailingTestCase()
{
std::auto_ptr<MyObject> a(new MyObject());
a->f();
}
Greetings from Bremen,
Daniel Krügler
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net