diff options
author | Marek Polacek <polacek@redhat.com> | 2022-07-15 09:51:50 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-07-26 08:01:33 -0400 |
commit | 2333b58c9892667545d0c2c3ecd2d7b947197511 (patch) | |
tree | ccd386e88fb9b661e0bfd8c0f387d7ea9d3155ee /gcc | |
parent | 2615502971ca11c15f1949c03d93ccfe1ce54f55 (diff) | |
download | gcc-2333b58c9892667545d0c2c3ecd2d7b947197511.zip gcc-2333b58c9892667545d0c2c3ecd2d7b947197511.tar.gz gcc-2333b58c9892667545d0c2c3ecd2d7b947197511.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/pt.cc | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/redecl5.C | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c415db3..6c581fe0 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 0000000..fb2d698 --- /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" } |