public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1841] c++: ICE with erroneous template redeclaration [PR106311] Date: Tue, 26 Jul 2022 12:04:52 +0000 (GMT) [thread overview] Message-ID: <20220726120452.961F73858D32@sourceware.org> (raw) https://gcc.gnu.org/g:2333b58c9892667545d0c2c3ecd2d7b947197511 commit r13-1841-g2333b58c9892667545d0c2c3ecd2d7b947197511 Author: Marek Polacek <polacek@redhat.com> Date: Fri Jul 15 09:51:50 2022 -0400 c++: ICE with erroneous template redeclaration [PR106311] Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens to be error_mark_node in this ill-formed test. I kept running into this while reducing code, so it'd be good to have it fixed. PR c++/106311 gcc/cp/ChangeLog: * pt.cc (redeclare_class_template): Check DECL_P before accessing DECL_SOURCE_LOCATION. gcc/testsuite/ChangeLog: * g++.dg/template/redecl5.C: New test. Diff: --- gcc/cp/pt.cc | 5 ++++- gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c415db304c9..6c581fe0fb7 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -6377,7 +6377,10 @@ redeclare_class_template (tree type, tree parms, tree cons) { auto_diagnostic_group d; error ("template parameter %q+#D", tmpl_parm); - inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm); + if (DECL_P (parm)) + inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm); + else + inform (input_location, "redeclared here"); return false; } diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C new file mode 100644 index 00000000000..fb2d698e6bc --- /dev/null +++ b/gcc/testsuite/g++.dg/template/redecl5.C @@ -0,0 +1,5 @@ +// PR c++/106311 +// { dg-do compile } + +template <typename, long> struct array; // { dg-error "template parameter" } +template <typename, size_t X> struct array { }; // { dg-error "declared" }
reply other threads:[~2022-07-26 12:04 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=20220726120452.961F73858D32@sourceware.org \ --to=mpolacek@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).