diff options
author | Jason Merrill <jason@redhat.com> | 2022-11-11 00:45:02 -1000 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-11-14 17:51:38 -0500 |
commit | c41bbfcaf9d6ef5b57a7e89bba70b861c08a686b (patch) | |
tree | 23c3fbf034db9747bc4e05a833d1b096e9e29ee4 /gcc/cp/pt.cc | |
parent | e7c12a921525b2aa27ca4814c42c63d61a6d954e (diff) | |
download | gcc-c41bbfcaf9d6ef5b57a7e89bba70b861c08a686b.zip gcc-c41bbfcaf9d6ef5b57a7e89bba70b861c08a686b.tar.gz gcc-c41bbfcaf9d6ef5b57a7e89bba70b861c08a686b.tar.bz2 |
c++: only declare satisfied friends
A friend declaration can only have constraints if it is defined. If
multiple instantiations of a class template define the same friend function
signature, it's an error, but that shouldn't happen if it's constrained to
only be declared in one instantiation.
Currently we don't mangle requirements, so the foos all mangle the same and
actually instantiating #1 will break, but for now we can test that they're
considered distinct.
gcc/cp/ChangeLog:
* pt.cc (tsubst_friend_function): Check satisfaction.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-friend11.C: New test.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r-- | gcc/cp/pt.cc | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 57917de..af96c5c 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11284,6 +11284,9 @@ tsubst_friend_function (tree decl, tree args) not_tmpl = DECL_TEMPLATE_RESULT (new_friend); new_friend_result_template_info = DECL_TEMPLATE_INFO (not_tmpl); } + else if (!constraints_satisfied_p (new_friend)) + /* Only define a constrained hidden friend when satisfied. */ + return error_mark_node; /* Inside pushdecl_namespace_level, we will push into the current namespace. However, the friend function should go |