bug in C++ compiler 14.0.0: nonvirtual function cannot be declared with "abstract" or "sealed" modifier

bug in C++ compiler 14.0.0: nonvirtual function cannot be declared with "abstract" or "sealed" modifier

Аватар пользователя Andrea B.

When:
 - a templated class inherits from one of the template arguments
 - a method overrides a (supposedly virtual) method of the base class, declarig it as "final", without declaring it "virtual" in the derived class
icpc comlains with

error: nonvirtual function cannot be declared with "abstract" or "sealed" modifier

while gcc (4.8.1) happily compiles the code.

How to reproduce:

class Base {
public:
  virtual const char * name() {
    return "Base";
  }
};
 

template <class B>
class Derived : public B {
public:
  const char * name() final {
    return "Derived";
  }
};

 Also, the error message is misleading, it should mention "override" or "final", not "abstract" or "sealed" (from C# ?).

8 сообщений / 0 новое
Последнее сообщение
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.
Аватар пользователя Andrea B.

And here is the actual error:

$ g++ -std=c++11 test.cpp -c -o test.o

$ icpc -std=c++11 test.cpp -c -o test.o
test.cpp(12): error: nonvirtual function cannot be declared with "abstract" or "sealed" modifier
const char * name() final {
^

compilation aborted for test.cpp (code 2)

Вложения: 

ВложениеРазмер
Скачать test.cpp195 байтов
Аватар пользователя Georg Zitzlsberger (Intel)

Hello,

Thank you for reporting. I agree that this case should be allowed and the error message has to be rephrased. We'll track that as DPD200388855 and I'll inform you once implemented.

The alternative is to apply the "virtual" keyword to the derived class' function as well.

Best regards,

Georg Zitzlsberger

Аватар пользователя Andrea B.

Цитата:

Georg Zitzlsberger (Intel) wrote:The alternative is to apply the "virtual" keyword to the derived class' function as well.

Yes, that's what we can do in the meantime.

Thanks,
.Andrea

Аватар пользователя Andrea B.

For the record - this is still open with

$ icpc -v

icpc version 14.0.1 (gcc version 4.8.0 compatibility)

Аватар пользователя Shahzad Malik MUZAFFAR

and it is also open in 14.0.2

Аватар пользователя Shahzad Malik MUZAFFAR

and looks like it is still open in "Intel C++ Composer XE 2015 Pre-Release beta"

Аватар пользователя Georg Zitzlsberger (Intel)

Hello,

DPD200388855 is still at engineering. Once there's some progress I'll update this thread.

Best regards,

Georg Zitzlsberger

Зарегистрируйтесь, чтобы оставить комментарий.