From patchwork Mon Jan 29 20:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1892490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZUbm087b; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TP0rb1hGTz23dQ for ; Tue, 30 Jan 2024 07:53:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA79B385803B for ; Mon, 29 Jan 2024 20:53:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 63E4C3858434 for ; Mon, 29 Jan 2024 20:53:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63E4C3858434 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63E4C3858434 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706561588; cv=none; b=hF+D0/UC7COGKdB54z2lyAUxaXwukIZcXCSKDu0xlWnRu1dWbcnvOKifyl+nRHRNvqCiJoCuim/fScmgCEJ1ty2XS7XWoVILsceA9+biTdqBgtCFo6MCWd9lIPqo8gEjuV4tG+VaSj1sgALNu6cHFrQ1NYJmhzSapMbkS0t2aSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706561588; c=relaxed/simple; bh=V6ilVIEBkSaisOy2GdNPmW2BKkIagTkHfGW59kTxFnk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qAIHSqKAtO6ufKuBS7KDK5YSz4Ee/57Zgryrn1iyk/QiUOBg1jNpkXNEG6JIjcA/QtSz2kR+XCL9A6c3KCiLneb4nLpdVrz80hv9BjRBmxz9oxyRt+TcghXGpKD/b2gIvXOCF0IhreHG4y7eui9kdxdzTzDpugGeHuuAqUdjIyo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706561586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IXlc2axYv0ezHzzamzvI7Y6fcp4OaOdGxtEf/61eHYk=; b=ZUbm087bcZobh445XJGa4nNH6QCAWAqhMVd1KNnuxTXiSRw6Pb/RA9lqVFFeZ+Gac2WeTh VPC30c1U1sNeXq2coyyYo1vMETY+7agPLGPgPt+fQ1VzxSkhMlod/2ALQxEOUxszmXa8Ad C2fkQINiKpdU+/PgcYXZXgDIQXfHuz4= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-UoGeyaUxP8G8K0TUepEndQ-1; Mon, 29 Jan 2024 15:53:05 -0500 X-MC-Unique: UoGeyaUxP8G8K0TUepEndQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7831ed4bb2aso601962985a.0 for ; Mon, 29 Jan 2024 12:53:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706561583; x=1707166383; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IXlc2axYv0ezHzzamzvI7Y6fcp4OaOdGxtEf/61eHYk=; b=aJVze5DwTCKlSHhXUoLQH+/wDsJIHt/qcK+LQhrqiswsXwi4MlW+IeISj2tB1/fghE jSyEMH7N+Lci31kLF1lpuGEp58UWRfgZcyphMtrUXjVNgSJC8aZPEuYelUfySx//7CMW 2EYwYI0xPmruFubpGi0Ok1LDVQpWcggcIYKsFnQu8JfUUI/ZrLQfMFTuByVd/Mt9Kvpk TJtHES4ciCbHbigVNUTMZRtlLfwuxPgjxTYwcB52L7Kd2y7G2W+rZbIiUvpiypEm8zXV FrHel8sBUYk55uTAAXLq++gBrn8P1U8sBW2xl7BfqO8pR614BTWqfCAXZbua7V9p5pOn 1evA== X-Gm-Message-State: AOJu0YxDcl18hKq+zb0+BlfnLMa0p3yvdnOZqQfXLtQfk1gebSa31KuI S4JcSNwAafcHfeQHhOsKFQVkzD5DWvwblO7jExNvogX2pQkGRod8HiWqXQO3C6TogyAUZTmd+n3 rcJJqToVptsaljZu/lsB2FjfAlW3Yr23pF58h7WLQBM3cZ+YYe3/bpgtiYawUPrthXUfsvwa2Md NF3bp0KPedCKgIXefTqe4IdWSLvsucQsVac5C3 X-Received: by 2002:a05:620a:51d9:b0:783:997a:aa81 with SMTP id cx25-20020a05620a51d900b00783997aaa81mr5482650qkb.72.1706561583478; Mon, 29 Jan 2024 12:53:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEA58kN5ZZggwoeXgqstb8axMc4bQTgMznzFRiXhCQSCkde0JYZjKOouWztLM8BRXvAEtOYLQ== X-Received: by 2002:a05:620a:51d9:b0:783:997a:aa81 with SMTP id cx25-20020a05620a51d900b00783997aaa81mr5482633qkb.72.1706561582992; Mon, 29 Jan 2024 12:53:02 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c9-20020ae9e209000000b0078401adad7fsm853901qkc.133.2024.01.29.12.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 12:53:02 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: unifying INTEGER_CST parm with type-dep arg [PR113644] Date: Mon, 29 Jan 2024 15:53:00 -0500 Message-ID: <20240129205300.2434466-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.440.gb50a608ba2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here when trying to unify P=42 A=T::value we ICE due to the latter's empty type, which same_type_p dislikes. If the argument has empty type then it can't be an INTEGER_CST, so unification should fail. PR c++/113644 gcc/cp/ChangeLog: * pt.cc (unify) : Handle NULL_TREE type. gcc/testsuite/ChangeLog: * g++.dg/template/nontype30.C: New test. --- gcc/cp/pt.cc | 3 ++- gcc/testsuite/g++.dg/template/nontype30.C | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/nontype30.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 74013533b0f..0d8dbc68962 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24953,7 +24953,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* Type INTEGER_CST can come from ordinary constant template args. */ case INTEGER_CST: case REAL_CST: - if (!same_type_p (TREE_TYPE (parm), TREE_TYPE (arg))) + if (TREE_TYPE (arg) == NULL_TREE + || !same_type_p (TREE_TYPE (parm), TREE_TYPE (arg))) return unify_template_argument_mismatch (explain_p, parm, arg); while (CONVERT_EXPR_P (arg)) arg = TREE_OPERAND (arg, 0); diff --git a/gcc/testsuite/g++.dg/template/nontype30.C b/gcc/testsuite/g++.dg/template/nontype30.C new file mode 100644 index 00000000000..926a7726547 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/nontype30.C @@ -0,0 +1,13 @@ +// PR c++/113644 + +template struct A { }; + +template void f(A<42>); +template void f(A); + +struct B { static const int value = 42; }; + +int main() { + A<42> a; + f(a); // { dg-error "ambiguous" } +}