public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, Patrick Palka <ppalka@redhat.com>
Subject: [pushed] c++: redeclare_class_template and ttps [PR110523]
Date: Mon, 10 Jul 2023 11:00:52 -0400	[thread overview]
Message-ID: <20230710150052.1793398-1-ppalka@redhat.com> (raw)

Tested on x86_64-pc-linux-gnu, pushed to trunk as obvious.

-- >8 --

Now that we cache level-lowered ttps we can end up processing the same
ttp multiple times via (multiple calls to) redeclare_class_template, so
we can't assume a ttp's DECL_CONTEXT is initially empty.

	PR c++/110523

gcc/cp/ChangeLog:

	* pt.cc (redeclare_class_template): Relax the ttp DECL_CONTEXT
	assert, and downgrade it to a checking assert.

gcc/testsuite/ChangeLog:

	* g++.dg/template/ttp37.C: New test.
---
 gcc/cp/pt.cc                          |  3 ++-
 gcc/testsuite/g++.dg/template/ttp37.C | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/ttp37.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index d7d774fd9e5..076f788281e 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -6388,7 +6388,8 @@ redeclare_class_template (tree type, tree parms, tree cons)
 	 DECL_CONTEXT of the template for which they are a parameter.  */
       if (TREE_CODE (parm) == TEMPLATE_DECL)
 	{
-	  gcc_assert (DECL_CONTEXT (parm) == NULL_TREE);
+	  gcc_checking_assert (DECL_CONTEXT (parm) == NULL_TREE
+			       || DECL_CONTEXT (parm) == tmpl);
 	  DECL_CONTEXT (parm) = tmpl;
 	}
     }
diff --git a/gcc/testsuite/g++.dg/template/ttp37.C b/gcc/testsuite/g++.dg/template/ttp37.C
new file mode 100644
index 00000000000..c5f4e99c20a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ttp37.C
@@ -0,0 +1,15 @@
+// PR c++/110523
+
+template<template<class> class>
+class basic_json;
+
+template<class>
+struct json_pointer {
+  template<template<class> class>
+  friend class basic_json;
+};
+
+template struct json_pointer<int>;
+template struct json_pointer<char>;
+template struct json_pointer<long>;
+template struct json_pointer<void>;
-- 
2.41.0.327.gaa9166bcc0


                 reply	other threads:[~2023-07-10 15:01 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=20230710150052.1793398-1-ppalka@redhat.com \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /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: link
Be 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).