- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page