https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71099
Bug ID: 71099 Summary: Misleading diagnostic message with 'virtual' used in out-of-line definitions of class template member functions Product: gcc Version: 7.0 Status: UNCONFIRMED Keywords: diagnostic Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rs2740 at gmail dot com Target Milestone: --- GCC correctly diagnoses the problem with this ill-formed code: struct foo { virtual void f(); }; virtual void foo::f() {} + g++ -std=c++14 -Wall -pedantic main.cpp main.cpp:5:1: error: 'virtual' outside class declaration virtual void foo::f() {} ^~~~~~~ But if `foo` is a template, the error message is significantly less helpful: template<class> struct foo { virtual void f(); }; template<class T> virtual void foo<T>::f() {} + g++ -std=c++14 -Wall -pedantic main.cpp main.cpp:7:1: error: templates may not be 'virtual' virtual void foo<T>::f() {} ^~~~~~~ Clang correctly diagnoses the problem in both cases ("main.cpp:7:1: error: 'virtual' can only be specified inside the class definition").