From patchwork Wed Mar 30 21:51:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1611407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=h+sB0yn3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTKsJ4zFMz9sFt for ; Thu, 31 Mar 2022 08:52:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B3193857404 for ; Wed, 30 Mar 2022 21:52:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B3193857404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648677120; bh=I5xCqg2tJZS3u/+kRtxmGuFyUZiOD5V2nv1bvQUkNmw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=h+sB0yn3SFosVgZU1BQ47EIS3wNHMek2DC0FnnJU3q4upLWpWgN78uGQ1kfC4vWaa AP6weLqf/sjZzXaaM9hbueCQu33dDMwVuDmhnkQDMJaK75/RtyGEZzRIczTjyp0IRG s47xjh19dMczYi2nRUpEQ6XDk3huzmxjU+V82Rwk= 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 8FD7B3839810 for ; Wed, 30 Mar 2022 21:51:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8FD7B3839810 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-twFNEx3RPiWiHxYpO0ehJw-1; Wed, 30 Mar 2022 17:51:11 -0400 X-MC-Unique: twFNEx3RPiWiHxYpO0ehJw-1 Received: by mail-qv1-f69.google.com with SMTP id t16-20020ad44850000000b00440e0f2a561so17070891qvy.11 for ; Wed, 30 Mar 2022 14:51:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=I5xCqg2tJZS3u/+kRtxmGuFyUZiOD5V2nv1bvQUkNmw=; b=PjsmRDdYDJx9ziCVWM3El9vbLgwdJDgwUC2NF2oa0+xuWPLlS2dhkfATMHuokfSYjJ a5BA9V9x2+aXI7vvWh4wfK8uKZQfLQX9/Ubi8uIkcXkTOLSYrqqQzyL05baimWtBW0vg Dl78aLelli0OgBePRCzC62r57uwFjg/0JvaudU6ad+yQ9gHESFXfIrWaMJeiWBVVLsu1 Cl3C+NPEyaXUS20ZKxE8CRZxOtvLxPNbLo3VFVrivHXKyZkh/qqeJjJ27eR/7Elw4M5s e3asoFHf+0LbJziE4Hd1q1WNnvdfKuP3mXiANX5+BUNtS1DwPxC9jlyZA61dkcC1u4Ft 1exw== X-Gm-Message-State: AOAM533vY2ssO1FX6ROmG9Ke0RpQhX1J8TNmvYGIpIVUVN4CnpWSn/kd /1DNP5Iiet3YNRdFbExJZW/VqxmwwhAXR9RdzsVmqKMoIl0LpWfTDh0utY1USn2uHrQUca7IJfW uQqq5mZnP4q/UZe+CQJwxObDeYxKNKrQAAwohmiRwLVC/MlXh4WYifpllEDYke7pIK9g= X-Received: by 2002:a05:620a:1424:b0:67d:2bc6:856b with SMTP id k4-20020a05620a142400b0067d2bc6856bmr1356574qkj.434.1648677070669; Wed, 30 Mar 2022 14:51:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydW00DuudTh9s3mkX70XKwhfQbgWKCO4laUIwSViFhmo9x/9njXXQhPOkqy7xE9nzVBfCwNw== X-Received: by 2002:a05:620a:1424:b0:67d:2bc6:856b with SMTP id k4-20020a05620a142400b0067d2bc6856bmr1356558qkj.434.1648677070336; Wed, 30 Mar 2022 14:51:10 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id d82-20020a376855000000b0067dacb03b6esm11207930qkc.130.2022.03.30.14.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 14:51:09 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: deduction for dependent class type of NTTP [PR105110] Date: Wed, 30 Mar 2022 17:51:07 -0400 Message-Id: <20220330215107.1833323-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.693.g805e0a6808 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_LOW, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here deduction for the P/A pair V/a spuriously fails with types ‘A’ and ‘const A’ have incompatible cv-qualifiers because the argument type is const, whereas the parameter type is non-const. Since the type of an NTTP is always cv-unqualified, it seems natural to ignore cv-qualifiers on the argument type before attempting to unify the two types. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/105110 gcc/cp/ChangeLog: * pt.cc (unify) : Ignore cv-quals on on the argument type of an NTTP before deducing from it. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class52.C: New test. --- gcc/cp/pt.cc | 5 +++-- gcc/testsuite/g++.dg/cpp2a/nontype-class52.C | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class52.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1acb5990c5c..cdd75d3b6ac 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24271,8 +24271,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, && !(strict & UNIFY_ALLOW_INTEGER) && TEMPLATE_PARM_LEVEL (parm) <= TMPL_ARGS_DEPTH (targs)) { - /* Deduce it from the non-type argument. */ - tree atype = TREE_TYPE (arg); + /* Deduce it from the non-type argument. As above, ignore + top-level quals here too. */ + tree atype = cv_unqualified (TREE_TYPE (arg)); RECUR_AND_CHECK_FAILURE (tparms, targs, tparm, atype, UNIFY_ALLOW_NONE, explain_p); diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class52.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class52.C new file mode 100644 index 00000000000..56163376afb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class52.C @@ -0,0 +1,13 @@ +// PR c++/105110 +// { dg-do compile { target c++20 } } + +template struct A { }; + +template struct B { }; + +template V> void f(B); + +int main() { + constexpr A a; + f(B{}); +}