How to use -Wsuggest-final-types/methods?

Paul Smith paul@mad-scientist.net
Wed Oct 26 13:17:00 GMT 2016


I don't really understand this option.  I enabled it but it warns for
essentially all of my classes which have any virtual methods.  For
example if I have Foo.h:

  class Foo {
      virtual bool bar();
    ...
  };

then Foo.cpp which implements Foo.  And then in another header somewhere
else I inherit from Foo and implement bar() differently (as a virtual
function).  However when GCC compiles Foo.cpp it can't see the other
header, so I guess it assumes no one inherits from Foo and suggests it
should be marked final:

  Declaring type 'class Foo' final would enable devirtualization of N calls

I mean sure, it would, but that would defeat the entire point (as I
understand it).

I don't really understand how/where this option is meant to be used. 
Ditto for -Wsuggest-final-methods.



More information about the Gcc-help mailing list