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 r13-2710] c++: modules ICE with typename friend Date: Sat, 17 Sep 2022 13:18:53 +0000 (GMT) [thread overview] Message-ID: <20220917131853.844AE3830885@sourceware.org> (raw) https://gcc.gnu.org/g:f4dad09c543eebc4d33cab277d691ed5646bcd65 commit r13-2710-gf4dad09c543eebc4d33cab277d691ed5646bcd65 Author: Patrick Palka <ppalka@redhat.com> Date: Sat Sep 17 09:16:53 2022 -0400 c++: modules ICE with typename friend A couple of xtreme-header-* modules tests began ICEing in C++23 mode ever since r13-2650-g5d84a4418aa962 which introduced into <ranges> a dependently scoped friend declaration: friend /* typename */ _OuterIter::value_type; This happens because the streaming code assumes a TYPE_P friend must be a class type, but here it's a TYPENAME_TYPE, which doesn't have a TEMPLATE_INFO or CLASSTYPE_BEFRIENDING_CLASSES. This patch tries to correct this in a minimal way. gcc/cp/ChangeLog: * module.cc (friend_from_decl_list): Don't consider CLASSTYPE_TEMPLATE_INFO for a TYPENAME_TYPE friend. (trees_in::read_class_def): Don't add to CLASSTYPE_BEFRIENDING_CLASSES for a TYPENAME_TYPE friend. gcc/testsuite/ChangeLog: * g++.dg/modules/typename-friend_a.C: New test. * g++.dg/modules/typename-friend_b.C: New test. Diff: --- gcc/cp/module.cc | 5 +++-- gcc/testsuite/g++.dg/modules/typename-friend_a.C | 11 +++++++++++ gcc/testsuite/g++.dg/modules/typename-friend_b.C | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f27f4d091e5..1a1ff5be574 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -4734,7 +4734,8 @@ friend_from_decl_list (tree frnd) if (TYPE_P (frnd)) { res = TYPE_NAME (frnd); - if (CLASSTYPE_TEMPLATE_INFO (frnd)) + if (CLASS_TYPE_P (frnd) + && CLASSTYPE_TEMPLATE_INFO (frnd)) tmpl = CLASSTYPE_TI_TEMPLATE (frnd); } else if (DECL_TEMPLATE_INFO (frnd)) @@ -12121,7 +12122,7 @@ trees_in::read_class_def (tree defn, tree maybe_template) { tree f = TREE_VALUE (friend_classes); - if (TYPE_P (f)) + if (CLASS_TYPE_P (f)) { CLASSTYPE_BEFRIENDING_CLASSES (f) = tree_cons (NULL_TREE, type, diff --git a/gcc/testsuite/g++.dg/modules/typename-friend_a.C b/gcc/testsuite/g++.dg/modules/typename-friend_a.C new file mode 100644 index 00000000000..aa426fe6cf0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/typename-friend_a.C @@ -0,0 +1,11 @@ +// { dg-additional-options "-fmodules-ts" } +export module foo; +// { dg-module-cmi foo } + +template<class T> +struct A { + friend typename T::type; + friend void f(A) { } +private: + static constexpr int value = 42; +}; diff --git a/gcc/testsuite/g++.dg/modules/typename-friend_b.C b/gcc/testsuite/g++.dg/modules/typename-friend_b.C new file mode 100644 index 00000000000..97da9d82e11 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/typename-friend_b.C @@ -0,0 +1,6 @@ +// { dg-additional-options "-fmodules-ts" } +module foo; + +struct C; +struct B { using type = C; }; +struct C { static_assert(A<B>::value == 42); };
reply other threads:[~2022-09-17 13:18 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=20220917131853.844AE3830885@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).