From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 6BD203851C16 for ; Wed, 6 Jan 2021 00:31:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6BD203851C16 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-26-utLjApGYN2emUCpoSxIeNA-1; Tue, 05 Jan 2021 19:31:38 -0500 X-MC-Unique: utLjApGYN2emUCpoSxIeNA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFEE5801AC3 for ; Wed, 6 Jan 2021 00:31:37 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-114-84.rdu2.redhat.com [10.10.114.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BC601349A; Wed, 6 Jan 2021 00:31:36 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Fix thinko in auto return type checking [PR98441] Date: Tue, 5 Jan 2021 19:31:32 -0500 Message-Id: <20210106003132.1304027-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.6 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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-List-Received-Date: Wed, 06 Jan 2021 00:31:41 -0000 This fixes a thinko in my r11-2085 patch: when I said "But only give the !late_return_type errors when funcdecl_p, to accept e.g. auto (*fp)() = f; in C++11" I should've done this, otherwise we give bogus errors mentioning "function with trailing return type" when there is none. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/98441 * decl.c (grokdeclarator): Move the !funcdecl_p check inside the !late_return_type block. gcc/testsuite/ChangeLog: PR c++/98441 * g++.dg/cpp0x/auto55.C: New test. --- gcc/cp/decl.c | 8 +++++--- gcc/testsuite/g++.dg/cpp0x/auto55.C | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto55.C diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index bf6f12c26a0..1a114a2e2d0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12241,10 +12241,12 @@ grokdeclarator (const cp_declarator *declarator, tree late_return_type = declarator->u.function.late_return_type; if (tree auto_node = type_uses_auto (type)) { - if (!late_return_type && funcdecl_p) + if (!late_return_type) { - if (current_class_type - && LAMBDA_TYPE_P (current_class_type)) + if (!funcdecl_p) + /* auto (*fp)() = f; is OK. */; + else if (current_class_type + && LAMBDA_TYPE_P (current_class_type)) /* OK for C++11 lambdas. */; else if (cxx_dialect < cxx14) { diff --git a/gcc/testsuite/g++.dg/cpp0x/auto55.C b/gcc/testsuite/g++.dg/cpp0x/auto55.C new file mode 100644 index 00000000000..5bd32ac890d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto55.C @@ -0,0 +1,13 @@ +// PR c++/98441 +// { dg-do compile { target c++11 } } + +struct a { + int& mfn(); +}; + +void fn() +{ + int& (a::*myvar1)(void) = &a::mfn; + auto& (a::*myvar2)(void) = &a::mfn; + auto (a::*myvar3)(void) = &a::mfn; +} base-commit: ad92bf4b165935b58195825dc8f089f53fd2710b -- 2.29.2