From patchwork Mon Feb 24 20:41:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1243449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520028-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=Rsi0GMKe; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LMjBcrsO; dkim-atps=neutral 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 48RDWn2RLtz9sNg for ; Tue, 25 Feb 2020 07:42:11 +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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=pQW3UaDk9hWZEAWJ 4lWkIuuJIpt4SpvDFn8LF8DBwYFpRnV3Ez2wqit5NtaNmv8Co7el65TflG4XfaIL P1Hpsp79Ld5QF98HYbKVNq4aDaRc7szvM7Mz3qcyfJyYoSb8so08PrsOBw+ewHs0 jFy2Q8QQGs56jOFDJ0siNUIbiMM= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=5RvJ8j9J6QMLI6Nvl/CRpA k/sIk=; b=Rsi0GMKenJMlIMCNrWWtp5702yox2FhPAgxCknlw+GKziHo3GXo525 89WzCGfKCnd1a578I3PEhEfHkcx3nZcoBK71PonLWQFG+OIho+9icPgcLg1W89aW SbNdq8KISNYPhETFf+VCmDvW66PVhxztuFn17ZegVACuw+1nClkWg= Received: (qmail 84919 invoked by alias); 24 Feb 2020 20:42:03 -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 84911 invoked by uid 89); 24 Feb 2020 20:42:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=P0388, p0388, intu_rvref, int4_lvref X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 20:42:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582576920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2Y9Fxp9kxm7Pfv+MNOTJZ5UBOr3kNxxkCULMGH0qglA=; b=LMjBcrsOFMVfMktpeYQL6swWwaqKy7UGGkT5ERBr5z1F+w+AYvDjLEFGOZHBQ5VJdM9aG3 z56bWfEhsGidIi8GSb527hvPyZOG9GtCv7SEaBL/Adz3IUC+k8XMpJ7H1klFYassDkddu+ 51Wf216/uUILd5gK4jc/5k23+211+yA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-LJCDb5Y1OnO7ITqdltl3XQ-1; Mon, 24 Feb 2020 15:41:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1918800D55 for ; Mon, 24 Feb 2020 20:41:57 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-127-158.rdu2.redhat.com [10.10.127.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AB58393; Mon, 24 Feb 2020 20:41:57 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Fix ICE with static_cast when converting from int[] [PR93862] Date: Mon, 24 Feb 2020 15:41:47 -0500 Message-Id: <20200224204147.415565-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com This ICEs since my patch for P0388, which allowed conversions to arrays of unknown bound, but not the reverse, so these two static_casts are ill-formed. [expr.static.cast]/3 says that "cv1 T1" and "cv2 T2" have to be reference-compatible and the comment in build_static_cast_1 says it too but then we actually use reference_related_p... Fixed thus. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2020-02-24 Marek Polacek PR c++/93862 - ICE with static_cast when converting from int[]. * call.c (reference_compatible_p): No longer static. * cp-tree.h (reference_compatible_p): Declare. * typeck.c (build_static_cast_1): Use reference_compatible_p instead if reference_related_p. * g++.dg/cpp0x/rv-cast7.C: New test. --- gcc/cp/call.c | 3 +-- gcc/cp/cp-tree.h | 1 + gcc/cp/typeck.c | 2 +- gcc/testsuite/g++.dg/cpp0x/rv-cast7.C | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/rv-cast7.C base-commit: a4dbb9b25a60143c699de55cd6226cebeb3b3c3e diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 7a7f07c9630..e07ee85c06e 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -204,7 +204,6 @@ static struct z_candidate *add_candidate conversion **, tree, tree, int, struct rejection_reason *, int); static tree source_type (conversion *); static void add_warning (struct z_candidate *, struct z_candidate *); -static bool reference_compatible_p (tree, tree); static conversion *direct_reference_binding (tree, conversion *); static bool promoted_arithmetic_type_p (tree); static conversion *conditional_conversion (tree, tree, tsubst_flags_t); @@ -1554,7 +1553,7 @@ reference_related_p (tree t1, tree t2) /* Returns nonzero if T1 is reference-compatible with T2. */ -static bool +bool reference_compatible_p (tree t1, tree t2) { /* [dcl.init.ref] diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c1aafa1de3a..140d5d88b61 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6357,6 +6357,7 @@ extern tree make_temporary_var_for_ref_to_temp (tree, tree); extern bool type_has_extended_temps (tree); extern tree strip_top_quals (tree); extern bool reference_related_p (tree, tree); +extern bool reference_compatible_p (tree, tree); extern int remaining_arguments (tree); extern tree perform_implicit_conversion (tree, tree, tsubst_flags_t); extern tree perform_implicit_conversion_flags (tree, tree, tsubst_flags_t, int); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c0c98dad980..103a1a439ec 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -7383,7 +7383,7 @@ build_static_cast_1 (location_t loc, tree type, tree expr, bool c_cast_p, if (TYPE_REF_P (type) && TYPE_REF_IS_RVALUE (type) && (clk = real_lvalue_p (expr)) - && reference_related_p (TREE_TYPE (type), intype) + && reference_compatible_p (TREE_TYPE (type), intype) && (c_cast_p || at_least_as_qualified_p (TREE_TYPE (type), intype))) { if (processing_template_decl) diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cast7.C b/gcc/testsuite/g++.dg/cpp0x/rv-cast7.C new file mode 100644 index 00000000000..0eea24f9e85 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-cast7.C @@ -0,0 +1,6 @@ +// PR c++/93862 - ICE with static_cast when converting from int[]. +// { dg-do compile { target c++11 } } + +int(&&intu_rvref)[]{1,2,3,4}; +int(&int4_lvref)[4] = static_cast(intu_rvref); // { dg-error "invalid .static_cast." } +int(&&int4_rvref)[4] = static_cast(intu_rvref); // { dg-error "invalid .static_cast." }