Reject virt-specifiers on friends and member templates

Reject virt-specifiers on friends and member templates
	* friend.c (do_friend): Diagnose virt-specifiers.
	* pt.c (push_template_decl_real): Diagnose virt-specifiers.

From-SVN: r213874
This commit is contained in:
Ville Voutilainen 2014-08-12 20:06:11 +03:00 committed by Jason Merrill
parent caff45a635
commit 253e34040c
4 changed files with 23 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2014-08-12 Ville Voutilainen <ville.voutilainen@gmail.com>
Reject virt-specifiers on friends and member templates
* friend.c (do_friend): Diagnose virt-specifiers.
* pt.c (push_template_decl_real): Diagnose virt-specifiers.
2014-08-09 Paolo Carlini <paolo.carlini@oracle.com>
* typeck2.c (check_narrowing): Add tsubst_flags_t parameter, change

View File

@ -427,6 +427,10 @@ do_friend (tree ctype, tree declarator, tree decl,
/* Every decl that gets here is a friend of something. */
DECL_FRIEND_P (decl) = 1;
if (DECL_OVERRIDE_P (decl) || DECL_FINAL_P (decl))
error ("friend declaration %qD may not have virt-specifiers",
decl);
/* Unfortunately, we have to handle attributes here. Normally we would
handle them in start_decl_1, but since this is a friend decl start_decl_1
never gets to see it. */

View File

@ -4737,6 +4737,11 @@ push_template_decl_real (tree decl, bool is_friend)
}
else if (TREE_CODE (decl) == FUNCTION_DECL)
{
if (member_template_p)
{
if (DECL_OVERRIDE_P (decl) || DECL_FINAL_P (decl))
error ("member template %qD may not have virt-specifiers", decl);
}
if (DECL_DESTRUCTOR_P (decl))
{
/* [temp.mem]

View File

@ -52,6 +52,14 @@ struct D5 : B
void D5::g() override {} // { dg-error "not allowed outside a class definition" }
void g() override {} // { dg-error "not allowed outside a class definition" }
struct B5
{
friend void f() final; // { dg-error "may not have virt-specifiers" }
friend void g() override; // { dg-error "may not have virt-specifiers" }
template <class T> void h() final; // { dg-error "may not have virt-specifiers" }
template <class T> void i() override; // { dg-error "may not have virt-specifiers" }
};
int main()
{
D2<B> d;