From patchwork Thu Jul 9 02:48:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1325689 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@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=MfdVNb3g; 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 4B2LGB3b9rz9sRK for ; Thu, 9 Jul 2020 12:48:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 286C6386188D; Thu, 9 Jul 2020 02:48:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 286C6386188D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594262911; bh=F19cNC/6RA6jgP+PscK+N5tNQmzP84RMjM0xL23326s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MfdVNb3gYWc9cb/sHK215gLLNDOlenXaVeOs/t0IX20hlw+00e8dDnZ9YpI6zCml3 HKZEqZ7R75p/GyjDEz5y90zVKJT7IAgazX5jWgrPa8URv0/IqL3Hnx52erTMiKWaoh pZsqm2pNogQB4FhZAW1+n4Ul2PA7VpbUZIF6u09U= 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 [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 2981F3858D34 for ; Thu, 9 Jul 2020 02:48:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2981F3858D34 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-115-M_GfkzhxPzucIW_r8dr4xA-1; Wed, 08 Jul 2020 22:48:27 -0400 X-MC-Unique: M_GfkzhxPzucIW_r8dr4xA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 115AD108BD11 for ; Thu, 9 Jul 2020 02:48:26 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-114-217.rdu2.redhat.com [10.10.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D0B679CEC; Thu, 9 Jul 2020 02:48:25 +0000 (UTC) To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Diagnose cv-qualified decltype(auto) [PR79815] Date: Wed, 8 Jul 2020 22:48:16 -0400 Message-Id: <20200709024816.1273734-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-15.7 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_NONE, RCVD_IN_MSPIKE_H2, 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" "If the placeholder is the decltype(auto) type-specifier, T shall be the placeholder alone." but we weren't detecting "const decltype(auto)". I've just expanded the existing diagnostic detecting "decltype(auto) &" and similar. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/79815 * decl.c (grokdeclarator): Detect cv-qual decltype(auto). * pt.c (do_auto_deduction): Likewise. gcc/testsuite/ChangeLog: PR c++/79815 * g++.dg/cpp1y/auto-fn58.C: New test. --- gcc/cp/decl.c | 17 +++++++++++++---- gcc/cp/pt.c | 6 ++++++ gcc/testsuite/g++.dg/cpp1y/auto-fn58.C | 8 ++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn58.C base-commit: 50873cc588fcc20384212b6dddca74393023a0e3 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 60a09e9497a..839ea8059e7 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12251,11 +12251,20 @@ grokdeclarator (const cp_declarator *declarator, /* Only plain decltype(auto) is allowed. */ if (tree a = type_uses_auto (type)) { - if (AUTO_IS_DECLTYPE (a) && a != type) + if (AUTO_IS_DECLTYPE (a)) { - error_at (typespec_loc, "%qT as type rather than " - "plain %", type); - return error_mark_node; + if (a != type) + { + error_at (typespec_loc, "%qT as type rather than " + "plain %", type); + return error_mark_node; + } + else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED) + { + error_at (typespec_loc, "% cannot be " + "cv-qualified"); + return error_mark_node; + } } } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b6423f7432b..33d194e9e15 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -28993,6 +28993,12 @@ do_auto_deduction (tree type, tree init, tree auto_node, error ("%qT as type rather than plain %", type); return error_mark_node; } + else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED) + { + if (complain & tf_error) + error ("% cannot be cv-qualified"); + return error_mark_node; + } } else { diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn58.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn58.C new file mode 100644 index 00000000000..8f6ec9b79ab --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn58.C @@ -0,0 +1,8 @@ +// PR c++/79815 +// { dg-do compile { target c++14 } } + +decltype(auto) const x = 1; // { dg-error "cannot be cv-qualified" } +volatile decltype(auto) x2 = 1; // { dg-error "cannot be cv-qualified" } +const volatile decltype(auto) x3 = 1; // { dg-error "cannot be cv-qualified" } +const decltype(auto) fn() { return 42; } // { dg-error "cannot be cv-qualified" } +const decltype(auto) fn2(); // { dg-error "cannot be cv-qualified" }