Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
7747 Discussions

Warning #2026 when compiling with icpc and -Wnon-virtual-dtor

Kempke__Nils-Christi
936 Views

Hi,

I was trying to compile some code of mine which, in g++ (with the --Wnon-virtual-dtor Flag) compiled just fine.

When I tried to compile the same code with Intel's icpc (actually this one icpc (ICC) 19.1.2.254 20200623) I got a warning which I was now able to track down - I'm wondering whether I'm somehow at fault or whether that warning is actually not correct in my case.

I wrote a somewhat minimal example of my class hierarchy:

 

 

template<typename T>
class B {
        public:
                B() = default;
                virtual ~B() = default;
};

template<typename T>
class C : public B<T> {
        public:
                C() = default;
                ~C() override = default;

                virtual int foo() { return 0; };
};

template<typename T>
class D : public C<T> {
        public:
                D() = default;
                ~D() override = default;
                int foo() override { return 1; };
};


int main() {
        return 0;
}

 

 

 

When compiling this with 

 

 

icpc -Wnon-virtual-dtor foo.cpp

 

 

I get the following warning:

 

 

foo.cpp(15): warning #2026: Effective C++ Item 14 Make sure base classes C have virtual destructors
};
^

 

 

 

One can get rid of the warning by explicitly stating that the destructor in C is virtual, so having

 

 

virtual ~C() override = default;

 

 

 

Note, that also getting rid of the template lets the code compile without any warning.

For last - also getting rid of the foo member function will let the code compile without warning.

So yeah - my question is: is this a "bug" in icpc or did I do something wrong?

 

Thanks in advance,
Nils

Labels (2)
0 Kudos
1 Solution
Viet_H_Intel
Moderator
883 Views

Compiler emits this spurious warning 2026. But since there is a workaround, we most likely are not going to fix it.


Thanks,


View solution in original post

5 Replies
VidyalathaB_Intel
Moderator
898 Views

Hi Nils,

Thanks for sharing the reproducer.

we tried it from our end and reproduced the same.

We are looking into this issue internally. We will get back to you soon.

Regards,

Vidya.


Viet_H_Intel
Moderator
884 Views

Compiler emits this spurious warning 2026. But since there is a workaround, we most likely are not going to fix it.


Thanks,


Viet_H_Intel
Moderator
807 Views

Hi Nils,

Can we close this thread?

Thanks,


Kempke__Nils-Christi
800 Views

Yes, sorry - I thought accepting a solution would somehow close it anyway, my bad.

Viet_H_Intel
Moderator
792 Views

Thanks.

This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.


Reply