This patch implements semantics for constrained friend templates and
classes. The only significant changes are in determine_specializaiton
and check_constrained_friend.

Unless a friend function is defined, a constraints on friend
declarations are never actually checked. The checking happens during
overload resolution against the actual (non-friend) declarations.

The change to determine_specialization is interesting. We have cases
where a programmer has written an explicit specialization and it's
being matched to a template. Previously, if constraints were not
satisfied, we would not record the template as a candidate. However,
this causes errors in class template instantiation if there are
constrained friend declarations whose constraints are not satisfied
("no matching template declaration").

With this patch, we defer constraints checks until we've selected the
best template for the specialization. And then we only check the
constraints if the declaration is a non-friend.

2013-09-13  Andrew Sutton  <andrew.n.sut...@gmail.com>
        * gcc/cp/cp-tree.h (check_constrained_friend): New.
        * gcc/cp/pt.c (determine_specialization): Only check constraints
        after determining which template the declaraiton is a specialization
        of. Don't check constraints for friends during class template
        instantiation.
        (fn_type_unification): New parameter to determine if constraints
        should be checked.
        (more_specialized_class): Update for interface change.
        (get_bindings): New parameter to determine if constraints should
        be checked during fn_type_unification. New overload that checks
        constraints by default.
        * gcc/cp/parser.c (cp_parser_member_declaration): Check constrained
        friends after parsing.
        * gcc/cp/class.c (resolve_address_of_overloaded_function): Update
        for interface change.
        * gcc/cp/call.c (is_non_template_friend): New.
        (add_function_candidate): Check constraints on constrained friend
        templates.
        (add_template_candidate_real): Update for interface change.
        * gcc/cp/constraint.c (check_constrained_friend): New.


Andrew Sutton

Attachment: friends.patch
Description: Binary data

Reply via email to