From patchwork Fri Aug 23 20:37:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1152422 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-507636-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="nrvFxzAr"; 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 46FYBB5BLLz9s7T for ; Sat, 24 Aug 2019 06:37:52 +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=Cs4IWXPACJamnh03hRJaqPFDF1DOatkyyOdA3e0DOOj7jRTd+SVt0 bB9y7Y6GkRdhA7Fnz652UV1DeWeMq1SijkQXjsiFp4cHXWSLAxRkKXqXl/rEwUzF h+Aa8vUh0PYu77yf0OHq15Bqc2GIb/CuxAZcP9x3qdmYFjq66krgnE= 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=JSy3pk5jtcNTPAZKhEOp0YCHbMQ=; b=nrvFxzArMirIGOhZiAlN L0h0QnJlQAq0QRj1c/QAZgZbUq1H2VbLgt3O6BcAv52ZoT5I6SaqkvEHrYicXuWN n1UYGTQ5gZSxja16TdpCzsxJ4jI9e1zyTWTYof8kFgZ+2n91XU9PCpL0Kh3d0qpS ZVi4Ty2+Jt/JqFABIo/rmxk= Received: (qmail 1395 invoked by alias); 23 Aug 2019 20:37:44 -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 1386 invoked by uid 89); 23 Aug 2019 20:37:44 -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=91521, r263836 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; Fri, 23 Aug 2019 20:37:43 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86FC8368CF for ; Fri, 23 Aug 2019 20:37:42 +0000 (UTC) Received: from redhat.com (unknown [10.20.4.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3760719C4F; Fri, 23 Aug 2019 20:37:42 +0000 (UTC) Date: Fri, 23 Aug 2019 16:37:40 -0400 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/91521 - wrong error with operator-> Message-ID: <20190823203740.GP14737@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) Since r263836 we enter the "a late-specified return type" block in grokdeclarator when inner_declarator is null: /* Handle a late-specified return type. */ tree late_return_type = declarator->u.function.late_return_type; - if (funcdecl_p) + if (funcdecl_p + /* This is the case e.g. for + using T = auto () -> int. */ + || inner_declarator == NULL) { inner_declarator is null in this testcase too, but here we don't have a real trailing return type; it's just an overloaded operator ->. That means that late_return_type is non-null, but is error_mark_node. In that case I think it's not sensible to complain about "trailing return type only available" or "function with trailing return type not declared with auto". In this case that made us reject valid code. Bootstrapped/regtested on x86_64-linux, ok for trunk and 9? 2019-08-23 Marek Polacek PR c++/91521 - wrong error with operator->. * decl.c (grokdeclarator): Don't consider error_mark_node a valid trailing return type. * g++.dg/parse/operator8.C: New test. diff --git gcc/cp/decl.c gcc/cp/decl.c index 88aa69ce5de..ea5752a249e 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -11546,6 +11546,7 @@ grokdeclarator (const cp_declarator *declarator, } } else if (late_return_type + && late_return_type != error_mark_node && sfk != sfk_conversion) { if (cxx_dialect < cxx11) diff --git gcc/testsuite/g++.dg/parse/operator8.C gcc/testsuite/g++.dg/parse/operator8.C new file mode 100644 index 00000000000..c5ee3eb934a --- /dev/null +++ gcc/testsuite/g++.dg/parse/operator8.C @@ -0,0 +1,13 @@ +// PR c++/91521 - wrong error with operator->. +// { dg-do compile } + +struct foo { + int bar() { return 0; } + foo* operator->() { return this; } +}; + +int main() +{ + int pt(foo()->bar()); + return pt; +}