Reject virt-specifiers on friends and member templates
authorVille Voutilainen <ville.voutilainen@gmail.com>
Tue, 12 Aug 2014 17:06:11 +0000 (20:06 +0300)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 12 Aug 2014 17:06:11 +0000 (13:06 -0400)
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

gcc/cp/ChangeLog
gcc/cp/friend.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/override1.C

index 47621ca0e868e0f93ae0b1b4a4843480d27a6c16..e30dc0e463603e3a6810a6f5487e0afbf001a5fe 100644 (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
index a30918c0006986149dd6eb4445f5ee2e403935ad..aa66c58568f42b40a028a9b83bd2e699250f5b3d 100644 (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.  */
index 25921722f3865202d7520b4a2c1b42cc86ad495d..90b2720ef9c8e7bec09b6e757dfb31073275dfcc 100644 (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]
index f5f00ee9f51b84cd956ded6dc213d9aeaa06c4b6..05d729084daa0987d0b8f7687350bff69172d605 100644 (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;