From patchwork Sat Nov 16 22:51:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1196223 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-513808-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="Dsz7L0jF"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="EH0PQAcq"; 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 47Fr7Y46TMz9sNH for ; Sun, 17 Nov 2019 09:51:51 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=S4MGNZsP23b9Y93GeWjhYDhijYibDg1VZ1VYhBj4sccC2l0k1x gjjrgngiNhI8wuv6UTWvwHJ9FkoNN3FHFHej6V3PSJXlR064H+Xz1hujozqj/bOY /om9u876dCgPvRJ+uMPwFi/RVF+SVLoYkFLYuditK4wt/DN/yUJQXgbv4= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=73t+PenscXkNIh1F/vZmcXNL48A=; b=Dsz7L0jFLC+lYokIxqsk Q3zldssacT0em2O9ZL3NsImkTcE2fZnv0gwmCYmAoJTaHscqYaHT3AfbbMaabVVs 2c6kuJ2hNgzz/EHAOgCBmjrZLy/+6TOVBsCXO9zEx6eh6mkBUqni3qc8d8Fw+CPv 2kHtwXAyv70FD7f9++VOMug= Received: (qmail 57796 invoked by alias); 16 Nov 2019 22:51:41 -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 57788 invoked by uid 89); 16 Nov 2019 22:51:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=sk:nested, sk:nested-, instantiate, substitute X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 16 Nov 2019 22:51:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573944695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=QxRloHKEKc4KMrXE1AtJJDEFKcCUbe8d0Mdt4g5ss0c=; b=EH0PQAcq18ePB0kmAlXwy8eAcfEdtM09REkz4lOVp3EOnWVwVpccYySfLLp5hLkDWyy/xa BfwsDytQQB3rbYUJtgsUsN73azFpO4OPvM2VTgOfnfbJJswyLmJblEr3CZt1jjaWK0DyrO 806tSNtXCk1imQqZPmhhTzbLHOC0tR4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-Th1V4yLuNjeNBneLwC_tGA-1; Sat, 16 Nov 2019 17:51:33 -0500 Received: by mail-qk1-f199.google.com with SMTP id l21so9041242qke.21 for ; Sat, 16 Nov 2019 14:51:33 -0800 (PST) Received: from [192.168.1.130] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id i68sm6295551qkb.106.2019.11.16.14.51.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Nov 2019 14:51:30 -0800 (PST) To: gcc-patches List From: Jason Merrill Subject: [C++ PATCH] Implement C++20 P1814R0, CTAD for alias templates. Message-ID: <6e852d48-36d7-6cb5-3364-9c3f1a7860a0@redhat.com> Date: Sat, 16 Nov 2019 17:51:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch implements C++20 class template argument deduction for alias templates, which works by a moderately arcane transformation of the deduction guides for the underlying class template. When implementing it, I found that I could simplify the rules in the draft a bit and get the same effect; I'll be emailing the committee to that effect soon. While working on this I ran into various shortcomings in our handling of constrained alias templates (like B in the testcase), and fixed those in a separate patch. Tested x86_64-pc-linux-gnu. I'm going to clean this up a bit more before checking it in, but am sending this functional patch now before the end of stage 1. commit 3784366a87f21dd0b995c1c952ab681165b99756 Author: Jason Merrill Date: Sat Nov 16 15:43:07 2019 -0500 Fix various issues with constrained alias templates. * cxx-pretty-print.c (pp_cxx_unqualified_id): Handle alias template-id. * pt.c (complex_alias_template_p): True if constraints. (get_underlying_template, tsubst): Check alias constraints. (push_template_decl_real): Set alias constraints here. * parser.c (cp_parser_alias_declaration): Not here. * constraint.cc (get_constraints): Take const_tree. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d6e9357385a..2a626d6d1ac 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7769,7 +7769,8 @@ extern cp_expr finish_constraint_and_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_primary_expr (cp_expr); extern tree finish_concept_definition (cp_expr, tree); extern tree combine_constraint_expressions (tree, tree); -extern tree get_constraints (tree); +extern tree append_constraint (tree, tree); +extern tree get_constraints (const_tree); extern void set_constraints (tree, tree); extern void remove_constraints (tree); extern tree current_template_constraints (void); diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 00b59a90868..c973d487245 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1119,7 +1119,7 @@ static GTY ((cache)) tree_cache_map *decl_constraints; constrained, return NULL_TREE. Note that T must be non-null. */ tree -get_constraints (tree t) +get_constraints (const_tree t) { if (!flag_concepts) return NULL_TREE; @@ -1129,7 +1129,7 @@ get_constraints (tree t) gcc_assert (DECL_P (t)); if (TREE_CODE (t) == TEMPLATE_DECL) t = DECL_TEMPLATE_RESULT (t); - tree* found = decl_constraints->get (t); + tree* found = decl_constraints->get (CONST_CAST_TREE (t)); if (found) return *found; else diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 8ece11d276e..909b2a4ef1d 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -172,11 +172,11 @@ pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t) case TYPENAME_TYPE: case UNBOUND_CLASS_TEMPLATE: pp_cxx_unqualified_id (pp, TYPE_NAME (t)); - if (CLASS_TYPE_P (t) && CLASSTYPE_USE_TEMPLATE (t)) + if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (t)) { pp_cxx_begin_template_argument_list (pp); - pp_cxx_template_argument_list (pp, INNERMOST_TEMPLATE_ARGS - (CLASSTYPE_TI_ARGS (t))); + tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti)); + pp_cxx_template_argument_list (pp, args); pp_cxx_end_template_argument_list (pp); } break; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c473e7fd92f..a80b4c818bb 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19891,14 +19891,6 @@ cp_parser_alias_declaration (cp_parser* parser) if (decl == error_mark_node) return decl; - /* Attach constraints to the alias declaration. */ - if (flag_concepts && current_template_parms) - { - tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); - tree constr = build_constraints (reqs, NULL_TREE); - set_constraints (decl, constr); - } - cp_finish_decl (decl, NULL_TREE, 0, NULL_TREE, 0); if (pushed_scope) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 8f7734a7a41..08b4713035b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5986,9 +5986,18 @@ push_template_decl_real (tree decl, bool is_friend) } if (TREE_CODE (decl) == TYPE_DECL - && TYPE_DECL_ALIAS_P (decl) - && complex_alias_template_p (tmpl)) - TEMPLATE_DECL_COMPLEX_ALIAS_P (tmpl) = true; + && TYPE_DECL_ALIAS_P (decl)) + { + if (tree constr + = TEMPLATE_PARMS_CONSTRAINTS (DECL_TEMPLATE_PARMS (tmpl))) + { + /* ??? Why don't we do this here for all templates? */ + constr = build_constraints (constr, NULL_TREE); + set_constraints (decl, constr); + } + if (complex_alias_template_p (tmpl)) + TEMPLATE_DECL_COMPLEX_ALIAS_P (tmpl) = true; + } } /* The DECL_TI_ARGS of DECL contains full set of arguments referring @@ -6335,6 +6344,9 @@ uses_all_template_parms_r (tree t, void *data_) static bool complex_alias_template_p (const_tree tmpl) { + if (get_constraints (tmpl)) + return true; + struct uses_all_template_parms_data data; tree pat = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl)); tree parms = DECL_TEMPLATE_PARMS (tmpl); @@ -6403,7 +6415,8 @@ get_underlying_template (tree tmpl) break; tree alias_args = INNERMOST_TEMPLATE_ARGS (generic_targs_for (tmpl)); - if (!comp_template_args (TI_ARGS (tinfo), alias_args)) + if (!comp_template_args (TI_ARGS (tinfo), alias_args) + || !equivalently_constrained (tmpl, underlying)) break; /* Alias is equivalent. Strip it and repeat. */ @@ -14896,6 +14909,18 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) instantiate it. */ tree tmpl = most_general_template (DECL_TI_TEMPLATE (decl)); tree gen_args = tsubst (DECL_TI_ARGS (decl), args, complain, in_decl); + /* FIXME check for satisfaction in check_instantiated_args. */ + if (flag_concepts + && !any_dependent_template_arguments_p (gen_args) + && !constraints_satisfied_p (tmpl, gen_args)) + { + if (complain & tf_error) + { + gcc_assert (seen_error ()); + diagnose_constraints (input_location, tmpl, args); + } + return error_mark_node; + } r = instantiate_alias_template (tmpl, gen_args, complain); } else if (DECL_CLASS_SCOPE_P (decl)