From patchwork Thu Jun 3 18:04:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1487372 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: 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=tRdg0e0o; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 ozlabs.org (Postfix) with ESMTPS id 4Fwv221D6qz9s1l for ; Fri, 4 Jun 2021 04:05:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 856C7399000B for ; Thu, 3 Jun 2021 18:05:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 856C7399000B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622743511; bh=8ABYx1Rq1zV1Q5natYSgOZM/3WO459cs3raYw9taYYM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tRdg0e0oX37PsFWpKjN4iWovSYm+iP0D2Kyt+WMMMixlq2hgHT7cqcwIFzrlcXGJK HqWrciYZVXNkEW7hx5WIWyEC2HqeoTNTlC2zVbHHSxOrMjywITQzzYt/KpAq0y2MWh ZaRg3X4XNQeHpQRdBjh15UV78j9iRXfPb6jMOpyk= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 7A0573857C75 for ; Thu, 3 Jun 2021 18:04:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A0573857C75 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423-gYciYhmAMHGcxS5QtRBjvQ-1; Thu, 03 Jun 2021 14:04:22 -0400 X-MC-Unique: gYciYhmAMHGcxS5QtRBjvQ-1 Received: by mail-qk1-f198.google.com with SMTP id u9-20020a05620a4549b02902e956c2a3c8so4859600qkp.20 for ; Thu, 03 Jun 2021 11:04:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8ABYx1Rq1zV1Q5natYSgOZM/3WO459cs3raYw9taYYM=; b=dih2Yk7qzSklCW6I8FczpKoJCZkHbR4f+kV/64P9V+kv6oCV3gaCqoDuY1mfmczo5N E7gsuqXA8QQaUcJQ1ObMHHDAuHnMdIIW1CWJ45NyF9ETAZFuEGhfj2vGQ9kf/Ta2p8Bn fHoNKKwu46SPs1PO1PTmJoLfSLylQAY7t1FgDTKf7x8t8+FWQhYr5sDfvZDQzibUSs7W l6+i006LSEgkPqwBXFr3kEszhauJj//1/6RHTXkIAawRJ/SfDo0vWF7o+lJV70My1rfj gjCwU9YwZ4am5nAbtDXkAlYuQmqOfXgtz4ffH6TxDG9RlBJFr8//JaWDzQpOd+qTMUxQ shWg== X-Gm-Message-State: AOAM532hCxJdsmJ1+aMEykTrLqCBSjywCbUpvEgz7oocXq7pTOqtUNgb Ak4FJUj0Lm1ri32WwiRzqzbULNamvihZ5B3hKGtaJAr2RpgbkwFqTqMfpPxCrGVAd6oHlFBiGN3 +qDiQDP55Tp5OfwebF8cnqJEAMqRqFiOPyDJpH2JA7d8jza3ROntD7cCCHWtIZxyWcyw= X-Received: by 2002:ac8:718b:: with SMTP id w11mr696970qto.354.1622743461593; Thu, 03 Jun 2021 11:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeXyRdF/Kru0Mb2xbVvC5786GNW1BYiNsiblkPtQEuwAkkR5ksxzB+L+egjnfslDjLApL7LA== X-Received: by 2002:ac8:718b:: with SMTP id w11mr696943qto.354.1622743461227; Thu, 03 Jun 2021 11:04:21 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id y20sm2084495qtv.64.2021.06.03.11.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 11:04:20 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: top-level cv-quals on type of NTTP [PR100893] Date: Thu, 3 Jun 2021 14:04:19 -0400 Message-Id: <20210603180419.1888999-1-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.1 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, we're rejecting the specialization of g with T=A, F=&f in the first testcase due to a spurious constness mismatch between the type of the template argument &f and the substituted type of F (the substituted type has a top-level const). Note that this mismatch doesn't occur with object pointers because in that case a call to perform_qualification_conversions from convert_nontype_argument implicitly adds a top-level const to the argument (via a cast) to match. This however seems to be a manifestation of a more general conformance issue -- that we're not dropping top-level cv-quals after substituting into the type of an NTTP as per [temp.param]/6 (we only do so at parse time in process_template_parm). This patch makes convert_template_argument drop top-level cv-quals accordingly. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/100893 gcc/cp/ChangeLog: * pt.c (convert_template_argument): Strip top-level cv-quals on the substituted type of a non-type template parameter. gcc/testsuite/ChangeLog: * g++.dg/template/param4.C: New test. * g++.dg/template/param5.C: New test. --- gcc/cp/pt.c | 7 ++++++- gcc/testsuite/g++.dg/template/param4.C | 10 ++++++++++ gcc/testsuite/g++.dg/template/param5.C | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/param4.C create mode 100644 gcc/testsuite/g++.dg/template/param5.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7211bdc5bbc..66cc88a331f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8494,7 +8494,12 @@ convert_template_argument (tree parm, return error_mark_node; } else - t = tsubst (t, args, complain, in_decl); + { + t = tsubst (t, args, complain, in_decl); + /* Ignore top-level qualifiers on the substituted type of this + non-type template parameter, as per [temp.param]/6. */ + t = cv_unqualified (t); + } if (invalid_nontype_parm_type_p (t, complain)) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/template/param4.C b/gcc/testsuite/g++.dg/template/param4.C new file mode 100644 index 00000000000..d55fecec2d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param4.C @@ -0,0 +1,10 @@ +// PR c++/100893 + +template void g() { } + +struct A { typedef void (* const type)(); }; +void f(); +template void g(); + +struct B { typedef void (B::* const type)(); void f(); }; +template void g(); diff --git a/gcc/testsuite/g++.dg/template/param5.C b/gcc/testsuite/g++.dg/template/param5.C new file mode 100644 index 00000000000..b8c92f4c217 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param5.C @@ -0,0 +1,7 @@ +// Verify top-level cv-qualifiers are dropped when determining the substituted +// type of a non-type-template parameter, as per [temp.param]/6. +// { dg-do compile { target c++11 } } + +template decltype(V)& f(); +using type = decltype(f()); +using type = int&;