I like to compile my code using -Wsuggest-final-types
and -Wsuggest-final-methods
to get warnings about the possibilities of using a keyword final
so that the compiler can optimize more aggressively.
Sometimes, however, the sentences are incorrect - for example, I have a class Base
with a destructor virtual ~Base()
that is used polymorphically in another project, and gcc offers me so that I Base
can mark it as final
.
Is there a way to “purely” tell the compiler that it is Base
used polymorphically and should not be marked as final
?
The only way I can think of is to use directives #pragma
, but I find this makes the code cluttered and hard to read.
Ideally, I am looking for a keyword or attribute non-final
that can be added / added to a class / method declaration.
source
share