From patchwork Fri Dec 19 07:21:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 422784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 96AEC1400A0 for ; Fri, 19 Dec 2014 18:21:36 +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 :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=C14veFCM7GoA8xJeQ3g0htpc3lEJnP1O1HOzypL1f5/Qq+ XdHvHskMaN4lzMtXKD2z9bn4POkFt1JSOExRDOCHt3bWkrST9yKRfr99PMDoQdCI GHuPZlpU6KDuxBrxWywhY18Mu+2X0C60UwGekTHyX+QMLX+saYr5O6R5oNQ9U= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=Uiwm3KVej83VUBhCVIVMFOZ+DeA=; b=AmY36Z4cIv+taYjPtcH+ MD0HUs1Zi8VIdD/jcLE3kBQH1DLHWDvaxgIK+vfSbr9H5NuP22XWoPTWFtbXt43V MODkrGhva8nXINi8oUuN+bqo4MppOcoAIPpNWvNx1/qKD55Yi9821GYfDTEsz4de Zhn9/q8iKor0I5VxQ/CojnI= Received: (qmail 5266 invoked by alias); 19 Dec 2014 07:21:28 -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 5251 invoked by uid 89); 19 Dec 2014 07:21:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f181.google.com Received: from mail-ob0-f181.google.com (HELO mail-ob0-f181.google.com) (209.85.214.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 19 Dec 2014 07:21:24 +0000 Received: by mail-ob0-f181.google.com with SMTP id gq1so11255703obb.12 for ; Thu, 18 Dec 2014 23:21:22 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.60.46.196 with SMTP id x4mr3886136oem.78.1418973682867; Thu, 18 Dec 2014 23:21:22 -0800 (PST) Received: by 10.76.154.2 with HTTP; Thu, 18 Dec 2014 23:21:22 -0800 (PST) Date: Fri, 19 Dec 2014 09:21:22 +0200 Message-ID: Subject: [C++ PATCH] Reject trailing return type for operator auto() From: Ville Voutilainen To: "gcc-patches@gcc.gnu.org" , Jason Merrill Tested on Linux-x64. /cp 2014-12-19 Ville Voutilainen Reject trailing return type for an operator auto(). * decl.c (grokdeclarator): Reject trailing return types for all conversion operators, don't handle conversion operators in the previous checks that deal with auto. /testsuite 2014-12-19 Ville Voutilainen Reject trailing return type for an operator auto(). * g++.dg/cpp0x/auto9.C: Adjust. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index bbaf3d6..5ff8cab 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9775,7 +9775,7 @@ grokdeclarator (const cp_declarator *declarator, virtualp = false; } } - else if (!is_auto (type)) + else if (!is_auto (type) && sfk != sfk_conversion) { error ("%qs function with trailing return type has" " %qT as its type rather than plain %", @@ -9783,7 +9783,8 @@ grokdeclarator (const cp_declarator *declarator, return error_mark_node; } } - else if (declarator->u.function.late_return_type) + else if (declarator->u.function.late_return_type + && sfk != sfk_conversion) { if (cxx_dialect < cxx11) /* Not using maybe_warn_cpp0x because this should @@ -9892,6 +9893,8 @@ grokdeclarator (const cp_declarator *declarator, maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION); explicitp = 2; } + if (late_return_type_p) + error ("a conversion function cannot have a trailing return type"); } arg_types = grokparms (declarator->u.function.parameters, diff --git a/gcc/testsuite/g++.dg/cpp0x/auto9.C b/gcc/testsuite/g++.dg/cpp0x/auto9.C index 0c0f39f..83efbaa 100644 --- a/gcc/testsuite/g++.dg/cpp0x/auto9.C +++ b/gcc/testsuite/g++.dg/cpp0x/auto9.C @@ -21,8 +21,8 @@ struct A struct A2 { - operator auto () -> int; // { dg-error "invalid use of" "" { target { ! c++14 } } } - operator auto *() -> int; // { dg-error "auto" } + operator auto () -> int; // { dg-error "invalid use of|trailing return type" } + operator auto*() -> int; // { dg-error "invalid use of|trailing return type" } }; template struct B