public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1519] c++: is_specialization_of_friend confusion [PR109923] Date: Sat, 3 Jun 2023 13:27:24 +0000 (GMT) [thread overview] Message-ID: <20230603132724.C421A3858422@sourceware.org> (raw) https://gcc.gnu.org/g:38af81df6aac11d49f9378d1c628ccc3c815c3ff commit r14-1519-g38af81df6aac11d49f9378d1c628ccc3c815c3ff Author: Patrick Palka <ppalka@redhat.com> Date: Sat Jun 3 09:26:43 2023 -0400 c++: is_specialization_of_friend confusion [PR109923] The check for a non-template member function of a class template in is_specialization_of_friend is overbroad, and accidentally holds for a non-template hidden friend too, which for the testcase below causes the predicate to bogusly return true for decl = void non_templ_friend(A<int>, A<void>) friend_decl = void non_templ_friend(A<void>, A<void>) This patch refines the check appropriately. PR c++/109923 gcc/cp/ChangeLog: * pt.cc (is_specialization_of_friend): Fix overbroad check for a non-template member function of a class template. gcc/testsuite/ChangeLog: * g++.dg/template/friend79.C: New test. Diff: --- gcc/cp/pt.cc | 1 + gcc/testsuite/g++.dg/template/friend79.C | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index dae3815f62a..6b20c58ce66 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1319,6 +1319,7 @@ is_specialization_of_friend (tree decl, tree friend_decl) of a template class, we want to check if DECL is a specialization if this. */ if (TREE_CODE (friend_decl) == FUNCTION_DECL + && DECL_CLASS_SCOPE_P (friend_decl) && DECL_TEMPLATE_INFO (friend_decl) && !DECL_USE_TEMPLATE (friend_decl)) { diff --git a/gcc/testsuite/g++.dg/template/friend79.C b/gcc/testsuite/g++.dg/template/friend79.C new file mode 100644 index 00000000000..7603adf5bea --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend79.C @@ -0,0 +1,20 @@ +// PR c++/109923 + +template<class T> +struct A { +private: + int x; + +public: + A() : x(0) { } + + friend void non_templ_friend(A val, A<void> weird) { + val.x++; // always works + weird.x++; // { dg-error "private" } should only work when T=void + } +}; + +int main() { + non_templ_friend(A<void>(), A<void>()); // { dg-bogus "" } + non_templ_friend(A<int>(), A<void>()); // { dg-message "required from here" } +}
reply other threads:[~2023-06-03 13:27 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230603132724.C421A3858422@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).