@@ -4140,6 +4140,12 @@ check_tag_decl (cp_decl_specifier_seq *declspecs)
error_p = true;
if (declared_type == NULL_TREE && ! saw_friend && !error_p)
permerror (input_location, "declaration does not declare anything");
+ else if (declared_type != NULL_TREE && type_uses_auto (declared_type))
+ {
+ error ("%<auto%> can only be specified for variables "
+ "or function declarations");
+ return error_mark_node;
+ }
/* Check for an anonymous union. */
else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
&& TYPE_ANONYMOUS_P (declared_type))
new file mode 100644
@@ -0,0 +1,9 @@
+// Origin PR c++/51473
+// { dg-options "-std=c++11" }
+
+struct A
+{
+ auto friend struct B; // { dg-error "multiple types|can only be specified|friend" }
+};
+
+auto int; // { dg-error "multiple types|can only be specified for variables" }