From 906a9283a5d53f21f032af8e4a22358b1b0f1ec9 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 21 Dec 2018 03:34:06 +0000 Subject: [PATCH] PR c++/88196 - ICE with class non-type template parameter. * pt.c (convert_nontype_argument): If the expr is a PTRMEM_CST, also check if the type we're converting it to is TYPE_PTRMEM_P. * g++.dg/cpp0x/ptrmem-cst-arg1.C: Tweak dg-error. * g++.dg/cpp2a/nontype-class10.C: New test. * g++.dg/template/pr54858.C: Tweak dg-error. From-SVN: r267319 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/pt.c | 2 +- gcc/testsuite/ChangeLog | 7 ++++++ gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C | 2 +- gcc/testsuite/g++.dg/cpp2a/nontype-class10.C | 6 +++++ gcc/testsuite/g++.dg/template/pr54858.C | 24 ++++++++++---------- 6 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class10.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f6e07a3afdb..f4295f33d5e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-12-20 Marek Polacek + + PR c++/88196 - ICE with class non-type template parameter. + * pt.c (convert_nontype_argument): If the expr is a PTRMEM_CST, also + check if the type we're converting it to is TYPE_PTRMEM_P. + 2018-12-20 H.J. Lu PR c/51628 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d4ac034671a..18b093e7d2d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6775,7 +6775,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) to a null value, but otherwise still need to be of a specific form. */ if (cxx_dialect >= cxx11) { - if (TREE_CODE (expr) == PTRMEM_CST) + if (TREE_CODE (expr) == PTRMEM_CST && TYPE_PTRMEM_P (type)) /* A PTRMEM_CST is already constant, and a valid template argument for a parameter of pointer to member type, we just want to leave it in that form rather than lower it to a diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8a32fa8998f..d814641a966 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-12-20 Marek Polacek + + PR c++/88196 - ICE with class non-type template parameter. + * g++.dg/cpp0x/ptrmem-cst-arg1.C: Tweak dg-error. + * g++.dg/cpp2a/nontype-class10.C: New test. + * g++.dg/template/pr54858.C: Tweak dg-error. + 2018-12-20 H.J. Lu PR c/51628 diff --git a/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C b/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C index ed12655af32..38b3e24241c 100644 --- a/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C +++ b/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C @@ -5,5 +5,5 @@ template struct A {}; struct B { int i; - A<&B::i> a; // { dg-error "could not convert template argument" } + A<&B::i> a; // { dg-error "could not convert" } }; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class10.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class10.C new file mode 100644 index 00000000000..5cc179300ca --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class10.C @@ -0,0 +1,6 @@ +// PR c++/88196 +// { dg-do compile { target c++2a } } + +struct C { C *c; }; +template struct D; +D <&C::c> d; // { dg-error "could not convert" } diff --git a/gcc/testsuite/g++.dg/template/pr54858.C b/gcc/testsuite/g++.dg/template/pr54858.C index 51610ad689a..6d23decfbb9 100644 --- a/gcc/testsuite/g++.dg/template/pr54858.C +++ b/gcc/testsuite/g++.dg/template/pr54858.C @@ -5,17 +5,17 @@ template struct A {}; template struct B {}; template struct C { - A<0> c0; B, &C::c0> d0; // { dg-error "could not convert template argument" } - A<0> c1; B, &C::c1> d1; // { dg-error "could not convert template argument" } - A<0> c2; B, &C::c2> d2; // { dg-error "could not convert template argument" } - A<0> c3; B, &C::c3> d3; // { dg-error "could not convert template argument" } - A<0> c4; B, &C::c4> d4; // { dg-error "could not convert template argument" } - A<0> c5; B, &C::c5> d5; // { dg-error "could not convert template argument" } - A<0> c6; B, &C::c6> d6; // { dg-error "could not convert template argument" } - A<0> c7; B, &C::c7> d7; // { dg-error "could not convert template argument" } - A<0> c8; B, &C::c8> d8; // { dg-error "could not convert template argument" } - A<0> c9; B, &C::c9> d9; // { dg-error "could not convert template argument" } - A<0> ca; B, &C::ca> da; // { dg-error "could not convert template argument" } - A<0> cb; B, &C::cb> db; // { dg-error "could not convert template argument" } + A<0> c0; B, &C::c0> d0; // { dg-error "could not convert" } + A<0> c1; B, &C::c1> d1; // { dg-error "could not convert" } + A<0> c2; B, &C::c2> d2; // { dg-error "could not convert" } + A<0> c3; B, &C::c3> d3; // { dg-error "could not convert" } + A<0> c4; B, &C::c4> d4; // { dg-error "could not convert" } + A<0> c5; B, &C::c5> d5; // { dg-error "could not convert" } + A<0> c6; B, &C::c6> d6; // { dg-error "could not convert" } + A<0> c7; B, &C::c7> d7; // { dg-error "could not convert" } + A<0> c8; B, &C::c8> d8; // { dg-error "could not convert" } + A<0> c9; B, &C::c9> d9; // { dg-error "could not convert" } + A<0> ca; B, &C::ca> da; // { dg-error "could not convert" } + A<0> cb; B, &C::cb> db; // { dg-error "could not convert" } }; C e; -- 2.30.2