From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111511 invoked by alias); 20 Dec 2018 21:54:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 111495 invoked by uid 89); 20 Dec 2018 21:54:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Dec 2018 21:54:06 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E74A88E58 for ; Thu, 20 Dec 2018 21:54:05 +0000 (UTC) Received: from redhat.com (ovpn-123-255.rdu2.redhat.com [10.10.123.255]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0817B16922; Thu, 20 Dec 2018 21:54:03 +0000 (UTC) Date: Thu, 20 Dec 2018 22:19:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/88196, ICE with class non-type template parameter Message-ID: <20181220215403.GQ21364@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2018-12/txt/msg01509.txt.bz2 This testcase breaks in C++20 because convert_nontype_argument gets a PTRMEM_CST as the expression, and we're trying to convert it to a class type, which doesn't work, but because of the PTRMEM_CST check below we never diagnosed it. The comment says a PTRMEM_CST is a valid template argument for a parameter of pointer to member type, but it doesn't check that that's what we're converting it to. Fixed by adding such a check. Bootstrapped/regtested on x86_64-linux, ok for trunk? 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. * 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. diff --git gcc/cp/pt.c gcc/cp/pt.c index d4ac034671a..18b093e7d2d 100644 --- gcc/cp/pt.c +++ 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 gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C index ed12655af32..38b3e24241c 100644 --- gcc/testsuite/g++.dg/cpp0x/ptrmem-cst-arg1.C +++ 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 gcc/testsuite/g++.dg/cpp2a/nontype-class10.C gcc/testsuite/g++.dg/cpp2a/nontype-class10.C new file mode 100644 index 00000000000..5cc179300ca --- /dev/null +++ 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 gcc/testsuite/g++.dg/template/pr54858.C gcc/testsuite/g++.dg/template/pr54858.C index 51610ad689a..6d23decfbb9 100644 --- gcc/testsuite/g++.dg/template/pr54858.C +++ 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;