From patchwork Fri Jul 19 06:51:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1133915 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-505309-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.b="Abi0kIkD"; 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 45qhVw5P4zz9s7T for ; Fri, 19 Jul 2019 16:51:34 +1000 (AEST) 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-transfer-encoding; q=dns; s=default; b=AbOLp2mDCvX6flds Y21MbnBBZxE4cLGmLIWKUGLyw8AWT8KqJBXrMXgH/dRxsL7+lVx6YomVo1+KC5Nr ebMZwdJWqwEv8N/c9v23TqAIxaQE1ha8cxqtfyI1yFpd4wcZnh9pkVgGoVQdkU3O p17LPRrVYrecOwX5XnC39KsqW2M= 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-transfer-encoding; s=default; bh=9G+qYbtwf5lw3pEaC/iXmr pDr0M=; b=Abi0kIkDSlr54aZj8n51CtbhOeSdp/mZ8beqdILVPVXqdxt3+DIinz AVo7t1dVodeO3Se06/Upj6Fmoy3iHVsh+jIAQrsplyL6e/Y5RtvX33mWgpC5IenO qZkJRl+QsgjFH3MQytFs98+F1cNP7zT9sarewz8uq4tHxXveSW+uY= Received: (qmail 51265 invoked by alias); 19 Jul 2019 06:51:26 -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 51257 invoked by uid 89); 19 Jul 2019 06:51:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 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=unqualified X-HELO: mail-wm1-f66.google.com Received: from mail-wm1-f66.google.com (HELO mail-wm1-f66.google.com) (209.85.128.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Jul 2019 06:51:24 +0000 Received: by mail-wm1-f66.google.com with SMTP id a15so27653774wmj.5 for ; Thu, 18 Jul 2019 23:51:23 -0700 (PDT) Received: from localhost.localdomain ([62.153.214.124]) by smtp.gmail.com with ESMTPSA id o20sm70607039wrh.8.2019.07.18.23.51.20 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 23:51:21 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/90098 - partial specialization and class non-type parms. Date: Fri, 19 Jul 2019 08:51:19 +0200 Message-Id: <20190719065119.581-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes A non-type template parameter of class type used in an expression has const-qualified type; the pt.c hunks deal with this difference from the unqualified type of the parameter declaration. WAhen we use such a parameter as an argument to another template, we don't want to confuse things by copying it, we should pass it straight through. And we might as well skip copying other classes in constant evaluation context in a template, too; we'll get the copy semantics at instantiation time. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/90099 PR c++/90101 * call.c (build_converted_constant_expr_internal): Don't copy. * pt.c (process_partial_specialization): Allow VIEW_CONVERT_EXPR around class non-type parameter. (unify) [TEMPLATE_PARM_INDEX]: Ignore cv-quals. --- gcc/cp/call.c | 5 +++++ gcc/cp/pt.c | 11 +++++++---- gcc/testsuite/g++.dg/cpp2a/nontype-class18.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/nontype-class19.C | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp2a/nontype-class20.C | 13 +++++++++++++ gcc/cp/ChangeLog | 10 ++++++++++ 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class18.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class19.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class20.C base-commit: fe986d2422dcdfb0a8ecfc03c6ac144ad706de1e diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e597d7ac919..38d229b1f33 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4278,6 +4278,11 @@ build_converted_constant_expr_internal (tree type, tree expr, if (conv) { + /* Don't copy a class in a template. */ + if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue + && processing_template_decl) + conv = next_conversion (conv); + conv->check_narrowing = true; conv->check_narrowing_const_only = true; expr = convert_like (conv, expr, complain); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e23c0aaf325..53aaad1800a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4954,7 +4954,8 @@ process_partial_specialization (tree decl) simple identifier' condition and also the `specialized non-type argument' bit. */ && TREE_CODE (arg) != TEMPLATE_PARM_INDEX - && !(REFERENCE_REF_P (arg) + && !((REFERENCE_REF_P (arg) + || TREE_CODE (arg) == VIEW_CONVERT_EXPR) && TREE_CODE (TREE_OPERAND (arg, 0)) == TEMPLATE_PARM_INDEX)) { if ((!packed_args && tpd.arg_uses_template_parms[i]) @@ -22371,9 +22372,11 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* Template-parameter dependent expression. Just accept it for now. It will later be processed in convert_template_argument. */ ; - else if (same_type_p (non_reference (TREE_TYPE (arg)), - non_reference (tparm))) - /* OK */; + else if (same_type_ignoring_top_level_qualifiers_p + (non_reference (TREE_TYPE (arg)), + non_reference (tparm))) + /* OK. Ignore top-level quals here because a class-type template + parameter object is const. */; else if ((strict & UNIFY_ALLOW_INTEGER) && CP_INTEGRAL_TYPE_P (tparm)) /* Convert the ARG to the type of PARM; the deduced non-type diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class18.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class18.C new file mode 100644 index 00000000000..22f47884d08 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class18.C @@ -0,0 +1,17 @@ +// PR c++/90101 +// { dg-do compile { target c++2a } } + +template +struct A; + +template typename List> +struct A> {}; + +template typename List, auto V> +struct A> {}; + +template +struct B {}; + +struct X { int value; }; +A> a2; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class19.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class19.C new file mode 100644 index 00000000000..91267aca383 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class19.C @@ -0,0 +1,13 @@ +// PR c++/90099 +// { dg-do compile { target c++2a } } + +struct Unit { + int value; + // auto operator<=>(const Unit&) = default; +}; + +template +struct X {}; + +template +struct X {}; diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class20.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class20.C new file mode 100644 index 00000000000..5d3479c345e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class20.C @@ -0,0 +1,13 @@ +// PR c++/90098 +// { dg-do compile { target c++2a } } + +struct A { + int value; + // auto operator<=>(const A&) = default; +}; + +template +struct Z {}; + +template +struct Z {}; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c9091f523c5..cef36b2d1b2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2019-07-18 Jason Merrill + + PR c++/90098 - partial specialization and class non-type parms. + PR c++/90099 + PR c++/90101 + * call.c (build_converted_constant_expr_internal): Don't copy. + * pt.c (process_partial_specialization): Allow VIEW_CONVERT_EXPR + around class non-type parameter. + (unify) [TEMPLATE_PARM_INDEX]: Ignore cv-quals. + 2019-07-16 Jason Merrill * parser.c (make_location): Add overload taking cp_lexer* as last