From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116756 invoked by alias); 2 Dec 2017 00:13:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 116742 invoked by uid 89); 2 Dec 2017 00:13:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=weren't, friend 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; Sat, 02 Dec 2017 00:13:56 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95026C057F93; Sat, 2 Dec 2017 00:13:55 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 299705D6A2; Sat, 2 Dec 2017 00:13:55 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vB20DqbU027523; Sat, 2 Dec 2017 01:13:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vB20DnHG027522; Sat, 2 Dec 2017 01:13:49 +0100 Date: Sat, 02 Dec 2017 00:13:00 -0000 From: Jakub Jelinek To: Jason Merrill , Nathan Sidwell Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Diagnose = delete override of a friend function defined earlier (PR c++/80259) Message-ID: <20171202001349.GB2353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00081.txt.bz2 Hi! As the testcase shows, we weren't diagnosing the foo case in the testcase and would just silently overwrite old DECL_INITIAL with error_mark_node and ICE later on. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-12-01 Jakub Jelinek PR c++/80259 * decl2.c (grokfield): Diagnose = delete redefinition of a friend. * g++.dg/cpp0x/pr80259.C: New test. --- gcc/cp/decl2.c.jj 2017-11-21 08:43:50.000000000 +0100 +++ gcc/cp/decl2.c 2017-12-01 12:01:32.671514761 +0100 @@ -911,9 +911,18 @@ grokfield (const cp_declarator *declarat { if (init == ridpointers[(int)RID_DELETE]) { - DECL_DELETED_FN (value) = 1; - DECL_DECLARED_INLINE_P (value) = 1; - DECL_INITIAL (value) = error_mark_node; + if (friendp && decl_defined_p (value)) + { + error ("redefinition of %q#D", value); + inform (DECL_SOURCE_LOCATION (value), + "%q#D previously defined here", value); + } + else + { + DECL_DELETED_FN (value) = 1; + DECL_DECLARED_INLINE_P (value) = 1; + DECL_INITIAL (value) = error_mark_node; + } } else if (init == ridpointers[(int)RID_DEFAULT]) { --- gcc/testsuite/g++.dg/cpp0x/pr80259.C.jj 2017-12-01 12:06:54.611405404 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr80259.C 2017-12-01 12:06:19.000000000 +0100 @@ -0,0 +1,13 @@ +// PR c++/80259 +// { dg-do compile { target c++11 } } + +void foo () {} // { dg-message "previously defined here" } +void bar (); + +struct A +{ + friend void foo () = delete; // { dg-error "redefinition of" } + friend void bar () = delete; // { dg-message "previously defined here" } +}; + +void bar () {} // { dg-error "redefinition of" } Jakub