>> How do I apply -fno-devirtualize to just the class when it needs to be >> applied to a particular class's header file (and that header file is >> included elsewhere) ? > > I'm not sure this is possible via an option (or #pragma optimize). > -fdevirtualize applies to the call sites to a virtual functions, > not to the virtual function definitions. The only approach that > comes to mind is to annotate the callers with #pragma GCC optimize > ("no-devirtualize"). That works in 5.0 and a simple test case but > doesn't seem to work as I expect in 4.9. https://gcc.gnu.org/wiki/FAQ#optimize_attribute_broken