Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

dynamic_cast BUG on ICC 7.x for Linux

jonnyfat
Beginner
593 Views
EXAMPLE :

class BaseA
{
public:
virtual void op(){};
};

class BaseB
{
public:
virtual void op(){};
};

class DerivedA : public BaseA
{
public:
virtual void op(){};
};

class DerivedAAB : public DerivedA, public BaseB
{
public:
virtual void op(){};
};



int main(void)
{

DerivedAAB * DAAB = new DerivedAAB;

DerivedA * DA_DAAB = dynamic_cast(DAAB);

BaseB * BB3 = dynamic_cast(DA_DAAB);

if(BB3)
{
// WITH ICC 6.0.1 BB3 NOT NULL OK
printf("OK! ");
}
else
{
// WITH ICC 7.X BB3 NULL ERROR
printf("OOPS! ");
}
}
0 Kudos
5 Replies
murphsp1
Beginner
592 Views
gcc v3.2 also has a problem with dynamic_cast as I have discovered.

Check out bug report 9433 of the latest release of gcc (v3.2.2)

http://gcc.gnu.org/cgi-bin/gnatsweb.pl

It appears that the next release of gcc (v3.2.3) should fix this bug and it is due out on April 15th. If you are experiencing a similar bug using icc I wonder if this is due to both compilers using the same library/header . . .

Are you using RedHat 8.0?

Hope this helped
Sean
0 Kudos
ianmcculloch
Beginner
593 Views
I have an example where a dyamic_cast of a reference type seg-fault, but when rewritten as a cast of a pointer type it apparantly works OK. The crash is in

0x400606fe in __dynamic_cast () from /opt/intel/compiler70/ia32/lib/libcxa.so.3


#include

class Base
{
public:
virtual ~Base() {}
};

class Derived : public Base
{
public:
void foo() const { std::cout << "foo() called "; }
};

Base& obj()
{
static Derived d;
return d;
}

int main()
{
bool ShouldCrash = true; // set to false to get Derived::foo() called with no crash

if (ShouldCrash)
{
dynamic_cast(obj()).foo();
}
else
{
dynamic_cast(&obj())->foo();
}
}



Is anyone from Intel reading this?
0 Kudos
Ganesh_R_Intel
Employee
593 Views
Ian - I somehow missed this thread.
Please note that when you find what appears to be an issue in the compiler please dont hesitate to file an issue on the support website premier.intel.com.

Looking at this really briefly, I am not sure I know the cause for the error. Got to debug the runtime.

I am logging this internally and will keep you posted on any updates.
0 Kudos
murphsp1
Beginner
593 Views
Has any progress been made on uncovering this error?
0 Kudos
cp_jain
Beginner
593 Views
The original issue posted by jonnyfat seems to be fixed
in the latest Intel compiler.


[jain@jaffa jain]$ icpc test1.cpp
[jain@jaffa jain]$ ./a.out
OK!

[jain@jaffa jain]$ icpc -V
Intel C++ Compiler for 32-bit applications, Version 7.1 Build 20030507Z
...
...


CP
0 Kudos
Reply