Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

possible bug in icc family

ululi1970
Beginner
644 Views

The following snippet of code compiles on icc 2021.10.0 

 

struct A{
    virtual ~A() {};
    virtual void foo() = 0;
};
struct B : public A
{
    virtual void foo() {};
};
//  
int main(){
    A* x= new B;
    auto y = *x;
y.foo();
    return 0;
}

 

but fails at run time with the message

pure virtual method called
terminate called without an active exception 
 
which can be cryptic to read. Note that gcc and other compilers report an error at compile time that A is an abstract class. The only way to force an error at compile time in icc is to delete the copy constructor of A. 
 
OTOH, icx reports an error at compile time. 
 
 
 
 
Labels (1)
0 Kudos
1 Reply
Alex_Y_Intel
Moderator
553 Views

Please check your auto y = *x; 

Since A is an abstract class, it cannot be instantiated or copied. 

 

As for why icc can compile it... icc has long been deprecated and removed since oneAPI 2024 so you should migrate to using icx instead. 

0 Kudos
Reply