From patchwork Fri Feb 8 17:21:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1038802 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495532-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43x26Q4zT3z9s4V for ; Sat, 9 Feb 2019 04:21:48 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=TfsHTnoU7QmnPbXoITAwiDJvNwta8572WETdI0RLime5wAu+RqTGT 40FqbsiHn2nOyD1RAVQV1/icXu2nlytObvIetixiD6MtA/Q2c18oHxqxtKyXYbDl qoCSO3jGfpa9UWjxQvmkP4oarSeBsCddO2pgXVUZbfgxfhhJ8url74= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=5v8ucQngzGvfbRKb2RwPFc63zyw=; b=bSFzNO/bxj//HTRFEoi7 xRCh9k3U1cxRsAEOj+loLSIR8EPGrbpgl6xRG8LmzwjmYGJ5L38RH4G+fHa9kUEY mNeUc4U4RB/RSF3uQw2RrWM5XC8k2ANauD6Ez0/Oned0FtmGMvBvDTReD39TV4yT R0MeTygs5uIJy/Gglz4UUdk= Received: (qmail 19857 invoked by alias); 8 Feb 2019 17:21:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19844 invoked by uid 89); 8 Feb 2019 17:21:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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; Fri, 08 Feb 2019 17:21:39 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7DF540F2E for ; Fri, 8 Feb 2019 17:21:37 +0000 (UTC) Received: from redhat.com (ovpn-125-54.rdu2.redhat.com [10.10.125.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70BE75DF29; Fri, 8 Feb 2019 17:21:37 +0000 (UTC) Date: Fri, 8 Feb 2019 12:21:36 -0500 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/89212 - ICE converting nullptr to pointer-to-member-function Message-ID: <20190208172136.GL3884@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) r256999 removed early bailout for pointer-to-member-function types, so we now try to tsubst each element of a pointer-to-member-function CONSTRUCTOR. That's fine but the problem here is that we end up converting a null pointer to pointer-to-member-function type and that crashes in fold_convert: 16035 case INTEGER_CST: 16039 { 16040 /* Instantiate any typedefs in the type. */ 16041 tree type = tsubst (TREE_TYPE (t), args, complain, in_decl); 16042 r = fold_convert (type, t); It seems obvious to use cp_fold_convert which handles TYPE_PTRMEM_P, but that then ICEs too, the infamous "canonical types differ for identical types": type is struct { void A:: (struct A *) * __pfn; long int __delta; } and the type of "0" is "void A:: (struct A *) *". These types are structurally equivalent but have different canonical types. (What's up with that, anyway? It seems OK that the canonical type of the struct is the struct itself and that the canonical type of the pointer is the pointer itself.) That could be handled in cp_fold_convert: add code to convert an integer_zerop to TYPE_PTRMEMFUNC_P. Unfortunately the 0 is not null_ptr_cst_p because it's got a pointer type. Or just don't bother substituting null_member_pointer_value_p and avoid the above. Bootstrapped/regtested on x86_64-linux, ok for trunk and 8? 2019-02-08 Marek Polacek PR c++/89212 - ICE converting nullptr to pointer-to-member-function. * pt.c (tsubst_copy_and_build) : Return early for null member pointer value. * g++.dg/cpp0x/nullptr40.C: New test. diff --git gcc/cp/pt.c gcc/cp/pt.c index b8fbf4046f0..acc2d8f1feb 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -19251,6 +19251,9 @@ tsubst_copy_and_build (tree t, looked up by digest_init. */ process_index_p = !(type && MAYBE_CLASS_TYPE_P (type)); + if (null_member_pointer_value_p (t)) + RETURN (t); + n = vec_safe_copy (CONSTRUCTOR_ELTS (t)); newlen = vec_safe_length (n); FOR_EACH_VEC_SAFE_ELT (n, idx, ce) diff --git gcc/testsuite/g++.dg/cpp0x/nullptr40.C gcc/testsuite/g++.dg/cpp0x/nullptr40.C new file mode 100644 index 00000000000..21c188bdb5e --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/nullptr40.C @@ -0,0 +1,19 @@ +// PR c++/89212 +// { dg-do compile { target c++11 } } + +template using enable_if_t = int; + +template +struct p +{ + template> + p(T) { } + p() = default; +}; + +struct A +{ + p i = 1; + void bar(); + p j; +};