This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71099] New: Misleading diagnostic message with 'virtual' used in out-of-line definitions of class template member functions
- From: "rs2740 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 13 May 2016 08:49:28 +0000
- Subject: [Bug c++/71099] New: Misleading diagnostic message with 'virtual' used in out-of-line definitions of class template member functions
- Auto-submitted: auto-generated
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").