===================================================================
@@ -11460,7 +11460,8 @@ cp_parser_function_specifier_opt (cp_parser* parse
A member function template shall not be virtual. */
if (PROCESSING_REAL_TEMPLATE_DECL_P ())
error_at (token->location, "templates may not be %<virtual%>");
- set_and_check_decl_spec_loc (decl_specs, ds_virtual, token);
+ else
+ set_and_check_decl_spec_loc (decl_specs, ds_virtual, token);
break;
case RID_EXPLICIT:
@@ -29035,6 +29036,14 @@ finish_fully_implicit_template (cp_parser *parser,
{
gcc_assert (parser->fully_implicit_function_template_p);
+ if (member_decl_opt && member_decl_opt != error_mark_node
+ && DECL_VIRTUAL_P (member_decl_opt))
+ {
+ error_at (DECL_SOURCE_LOCATION (member_decl_opt),
+ "implicit templates may not be %<virtual%>");
+ DECL_VIRTUAL_P (member_decl_opt) = false;
+ }
+
pop_deferring_access_checks ();
if (member_decl_opt)
member_decl_opt = finish_member_template_decl (member_decl_opt);
===================================================================
@@ -0,0 +1,7 @@
+// PR c++/58535
+// { dg-options "-std=gnu++1y" }
+
+struct A
+{
+ virtual void foo(auto); // { dg-error "templates" }
+};
===================================================================
@@ -0,0 +1,6 @@
+// PR c++/58535
+
+struct A
+{
+ template<int> virtual void foo(); // { dg-error "templates" }
+};