2019-06-21 Marek Polacek <polacek@redhat.com>
+ PR c++/61490 - qualified-id in friend function definition.
+ * decl.c (grokdeclarator): Diagnose qualified-id in friend function
+ definition. Improve location for diagnostics of friend functions.
+
PR c++/60223 - ICE with T{} in non-deduced context.
* pt.c (unify): Allow COMPOUND_LITERAL_P in a non-deduced context.
friendp = 0;
}
if (decl_context == NORMAL)
- error ("friend declaration not in class definition");
+ error_at (declarator->id_loc,
+ "friend declaration not in class definition");
if (current_function_decl && funcdef_flag)
{
- error ("cannot define friend function %qs in a local "
- "class definition", name);
+ error_at (declarator->id_loc,
+ "cannot define friend function %qs in a local "
+ "class definition", name);
friendp = 0;
}
+ /* [class.friend]/6: A function can be defined in a friend
+ declaration if the function name is unqualified. */
+ if (funcdef_flag && in_namespace)
+ {
+ if (in_namespace == global_namespace)
+ error_at (declarator->id_loc,
+ "friend function definition %qs cannot have "
+ "a name qualified with %<::%>", name);
+ else
+ error_at (declarator->id_loc,
+ "friend function definition %qs cannot have "
+ "a name qualified with %<%D::%>", name,
+ in_namespace);
+ }
}
else if (ctype && sfk == sfk_conversion)
{
2019-06-21 Marek Polacek <polacek@redhat.com>
+ PR c++/61490 - qualified-id in friend function definition.
+ * g++.dg/diagnostic/friend2.C: New test.
+ * g++.dg/diagnostic/friend3.C: New test.
+
PR c++/60223 - ICE with T{} in non-deduced context.
* g++.dg/cpp0x/nondeduced1.C: New test.
* g++.dg/cpp0x/nondeduced2.C: New test.