From patchwork Fri Apr 17 13:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1272256 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=WdijJl+F; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 493cg35rVxz9s71 for ; Fri, 17 Apr 2020 23:40:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25052385C426; Fri, 17 Apr 2020 13:40:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25052385C426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587130845; bh=vltQMxw0At+n7zWnMXL+fxigTMRCu+LVweZ4LB96IcQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WdijJl+FWTrT+nbQ5zzuopUYCPdh3HUQSMvlQ+g6TJh8e7ZlHvG26/UCSuy6xPeJ/ VcO3GMB2OZhC0+GmRor28CFTJHMcBzq8BRTZaySZlqm+6UmpEWIst8R3f+/kPFX5n4 8a2+ZMccLeejZorUvn6sbuhq0Psnj8CWi6r//oZE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 08044385B835 for ; Fri, 17 Apr 2020 13:40:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 08044385B835 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-468-d78d7qIGNSiouXmV5gDSOg-1; Fri, 17 Apr 2020 09:40:40 -0400 X-MC-Unique: d78d7qIGNSiouXmV5gDSOg-1 Received: by mail-qv1-f71.google.com with SMTP id dh19so2192221qvb.23 for ; Fri, 17 Apr 2020 06:40:40 -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=N6SRQssrYW+lLDyO6M/XzgVEr/WhWKQ9rxXBBlO2tAs=; b=bLNt5zL/dQfBLmlysSgPSD/LYSY4V/DYq4IvegUUpC1O+M6nR1+Czehmss02pqYMHE P2jPAdEGQzvRst0cq5Qe/WFJ6ah7wvn45GzSM4nCEoUZxPi/42rsVytVIQJhdhxz8xJc uTguAAouBjhETaGzVyRvQecTmPxQgt53eyCrKoIE+yGWZMkWY0p7y0S+YxOvhKa3S3rg GfQ84tDKG7CUZz9XgvUeRDnF0y0JcZJn8r6Vw52fmr7eD+FFAIDmXKog/4uArda9vIoK 6C+yEMmIM3De2NIBnU7C89GqcdY6ngj2OHNfGOKCPYTls2iDsaoaim346/+Zf85CvYDb lhIw== X-Gm-Message-State: AGi0PubzDCUgNXhQQQPP21nRG+BmufwUZSWJGNQGRUegbdV7dQpLJ3D/ fRHmqHrmvRMJBMUiQFRCazlJYMheRkSH/6+MQ3NkRriZF0oRq01XdJds1p0chPkw4cF6LZooYyW 590qSYECuHTPwI3SMIg== X-Received: by 2002:a37:5d02:: with SMTP id r2mr3217193qkb.57.1587130839358; Fri, 17 Apr 2020 06:40:39 -0700 (PDT) X-Google-Smtp-Source: APiQypJoq+9BQHL8yVmrmfkbKJEP/a+TLeqqTd/JNPX+RNrWuu9XGher0mbv+ebt8kz3uFhSmrSmPQ== X-Received: by 2002:a37:5d02:: with SMTP id r2mr3217169qkb.57.1587130839051; Fri, 17 Apr 2020 06:40:39 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id p14sm16926386qkp.63.2020.04.17.06.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 06:40:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Abbreviated function template return type [PR92187] Date: Fri, 17 Apr 2020 09:40:36 -0400 Message-Id: <20200417134036.1876657-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.1.107.gefe3874640 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, 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@gcc.gnu.org Sender: "Gcc-patches" When updating an auto return type of an abbreviated function template in splice_late_return_type, we should also propagate PLACEHOLDER_TYPE_CONSTRAINTS (and cv-qualifiers) of the original auto node. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to commit? gcc/cp/ChangeLog: PR c++/92187 * pt.c (splice_late_return_type): Propagate cv-qualifiers and PLACEHOLDER_TYPE_CONSTRAINTS from the original auto node to the new one. gcc/testsuite/ChangeLog: PR c++/92187 * g++.dg/concepts/abbrev5.C: New test. * g++.dg/concepts/abbrev6.C: New test. --- gcc/cp/pt.c | 15 +++++++++++---- gcc/testsuite/g++.dg/concepts/abbrev5.C | 15 +++++++++++++++ gcc/testsuite/g++.dg/concepts/abbrev6.C | 12 ++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev5.C create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev6.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0a8ec3198d2..9e39f46a090 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -29032,10 +29032,17 @@ splice_late_return_type (tree type, tree late_return_type) { tree idx = get_template_parm_index (*auto_node); if (TEMPLATE_PARM_LEVEL (idx) <= processing_template_decl) - /* In an abbreviated function template we didn't know we were dealing - with a function template when we saw the auto return type, so update - it to have the correct level. */ - *auto_node = make_auto_1 (TYPE_IDENTIFIER (*auto_node), true); + { + /* In an abbreviated function template we didn't know we were dealing + with a function template when we saw the auto return type, so update + it to have the correct level. */ + tree new_auto = make_auto_1 (TYPE_IDENTIFIER (*auto_node), false); + PLACEHOLDER_TYPE_CONSTRAINTS (new_auto) + = PLACEHOLDER_TYPE_CONSTRAINTS (*auto_node); + TYPE_CANONICAL (new_auto) = canonical_type_parameter (new_auto); + new_auto = cp_build_qualified_type (new_auto, TYPE_QUALS (*auto_node)); + *auto_node = new_auto; + } } return type; } diff --git a/gcc/testsuite/g++.dg/concepts/abbrev5.C b/gcc/testsuite/g++.dg/concepts/abbrev5.C new file mode 100644 index 00000000000..de594b5c1df --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/abbrev5.C @@ -0,0 +1,15 @@ +// PR c++/92187 +// { dg-do compile { target concepts } } + +template +concept C = false; + +C auto f(auto) +{ + return 42; // { dg-error "deduced return type" } +} + +void foo() +{ + f(0); +} diff --git a/gcc/testsuite/g++.dg/concepts/abbrev6.C b/gcc/testsuite/g++.dg/concepts/abbrev6.C new file mode 100644 index 00000000000..862675e5193 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/abbrev6.C @@ -0,0 +1,12 @@ +// { dg-do compile { target concepts } } + +const auto &f(auto) +{ + static int n; + return n; +} + +void foo() +{ + f(5) = 0; // { dg-error "read-only" } +}