From patchwork Sun Sep 8 16:47:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1159508 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-508562-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="jyOFZiaz"; 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 46RHJr0Svtz9s7T for ; Mon, 9 Sep 2019 02:47:21 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=menf+HkE8SgdHkih3kFEydYaWL7UHE5IJza3W6iN2fbC7BQxS9U9j 9nHZvID9xQxmIP64ivE5npVSBSTIzW5z3d2B/BuymqZ0ctElLcoBvWSQfiZHDx9S kN68Wz7wEeyZL1oIX4yhh2pchm4LagfPRzaAJ03ru53DKpmQtJ88gs= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=HXytiOXIpM/eXbizZ0TlYumU1uk=; b=jyOFZiazvBaL8Zuq0r88 Upt9tAR7D6hIEW0AuojaHFBoJj+GJLvCE97Lr+22Wo1Gxcm+az+R0uSpnUu26SaZ z2nsc3hGdzOXYwhl0c3p33SrQ6CKepK0S3afwDa3y07tK8f7xEg/qSkODe1kg/Xu q2YAyXBn3LDaIC3GTdvPacg= Received: (qmail 36345 invoked by alias); 8 Sep 2019 16:47:14 -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 36337 invoked by uid 89); 8 Sep 2019 16:47:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=cpp1y, tmpl X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Sep 2019 16:47:13 +0000 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 mx1.redhat.com (Postfix) with ESMTPS id 126172D6A23 for ; Sun, 8 Sep 2019 16:47:12 +0000 (UTC) Received: from redhat.com (ovpn-126-230.rdu2.redhat.com [10.10.126.230]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A70C360610; Sun, 8 Sep 2019 16:47:11 +0000 (UTC) Date: Sun, 8 Sep 2019 12:47:09 -0400 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/84374 - diagnose invalid uses of decltype(auto) Message-ID: <20190908164709.GF14737@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) [dcl.type.auto.deduct]/5 "If the placeholder-type-specifier is of the form type-constraintopt decltype(auto), T shall be the placeholder alone." So, only plain decltype(auto) is allowed. But we aren't diagnosing it in function declarations, because do_auto_deduction is never called for those. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-09-08 Marek Polacek PR c++/84374 - diagnose invalid uses of decltype(auto). * decl.c (grokdeclarator): Diagnose wrong usage of decltype(auto) in a function declaration. * g++.dg/cpp1y/auto-fn57.C: New test. diff --git gcc/cp/decl.c gcc/cp/decl.c index 88e2c3beb2b..b1777730934 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -11560,6 +11560,14 @@ grokdeclarator (const cp_declarator *declarator, "cannot have deduced return type"); virtualp = false; } + else if (is_auto (auto_node) + && AUTO_IS_DECLTYPE (auto_node) + && type != auto_node) + { + error_at (typespec_loc, "%qT as type rather than " + "plain %", type); + return error_mark_node; + } } else if (!is_auto (type) && sfk != sfk_conversion) { @@ -11580,6 +11588,16 @@ grokdeclarator (const cp_declarator *declarator, "invalid use of %"); return error_mark_node; } + else if (tree a = type_uses_auto (late_return_type)) + { + if (AUTO_IS_DECLTYPE (a) && a != late_return_type) + { + error_at (typespec_loc, "%qT as type rather than " + "plain %", + late_return_type); + return error_mark_node; + } + } tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node); if (!tmpl) if (tree late_auto = type_uses_auto (late_return_type)) diff --git gcc/testsuite/g++.dg/cpp1y/auto-fn57.C gcc/testsuite/g++.dg/cpp1y/auto-fn57.C new file mode 100644 index 00000000000..e58df187df5 --- /dev/null +++ gcc/testsuite/g++.dg/cpp1y/auto-fn57.C @@ -0,0 +1,18 @@ +// PR c++/84374 - diagnose invalid uses of decltype(auto). +// { dg-do compile { target c++14 } } + +auto l = [](auto* r)->decltype(auto)* { return r; }; // { dg-error "as type rather than plain" } +auto m = [](auto* r)->decltype(auto)& { return *r; }; // { dg-error "as type rather than plain" } + +decltype(auto)* f(); // { dg-error "as type rather than plain" } +decltype(auto)& f2(); // { dg-error "as type rather than plain" } +decltype(auto)* f3() { return 42; } // { dg-error "as type rather than plain" } +decltype(auto)& f4() { return 42; } // { dg-error "as type rather than plain" } + + +class C { + decltype(auto)* g(); // { dg-error "as type rather than plain" } + decltype(auto)& g2(); // { dg-error "as type rather than plain" } + decltype(auto)* g3() { } // { dg-error "as type rather than plain" } + decltype(auto)& g4() { } // { dg-error "as type rather than plain" } +};