From patchwork Sat Apr 16 23:58:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 611416 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 3qnWbB2n9Tz9t6K for ; Sun, 17 Apr 2016 09:59:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=A39QQWMF; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=JlV+0j9qM8Oz sdNXDwMkzm57rRIyRqr07r8Mr0Jarya4g6GAAliuqfC91fBHuNWZv/0bQoXjlxWh AMDXJyn86QoFCaH6Y0zS8C2HbXooOnrZ9MEzFJ+XA3yliLKBDRgdV6nLw7AyqyqF jfbUWabm4HeeqOxaBZjTozq6GGk/iHE= 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:from :to:cc:subject:date:message-id; s=default; bh=3WIR3mhr4r33RokcS9 A7e8mCHqc=; b=A39QQWMFndwiSFc9jChishelqwbLLDGAb0qq61pOXjTKEfe2Vn qnc195/NDSQCucEJhvj8WDbRZzKJ2aAKOgWTWn7WuylJrr3km4rhr98FOA6bjQGH d167/2jaoAWrVX/nYaE9fxHAEgZjjURHS1LyDQsiGyIKrvLd6mw+6V8n8= Received: (qmail 31616 invoked by alias); 16 Apr 2016 23:58:51 -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 31596 invoked by uid 89); 16 Apr 2016 23:58:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=Hx-languages-length:2224, H*MI:ath, friend X-HELO: mail-qk0-f174.google.com Received: from mail-qk0-f174.google.com (HELO mail-qk0-f174.google.com) (209.85.220.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 16 Apr 2016 23:58:39 +0000 Received: by mail-qk0-f174.google.com with SMTP id r191so3077982qke.2 for ; Sat, 16 Apr 2016 16:58:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vsO1JUnmlT0UD0CMQxzJnCVldzr4/nV50RtnzxccaBo=; b=hvlGgKDLK2iHsWmcd5QVEsFrOgj2p/wlWtXziNN986TFRV7xBoxLgLpU+OvUSHUXFv hr7/wzjVK1zIYWG+i52vcVNCJQWmJSeuaKmo9yP57uCqPlE6bi8NtMDdE9E6YVcilRQ8 J0J1Bkf8OnE9GzgqRnJ+5QSKnJWjS16brE7Ym3RL84DKZ8ZvIxUyDRvcmVpac3Yp99WF 9ZsCU6om1vpw6/cPYuvB1Ey4OSWJZj1RzP6U/DuRY2587FhpGrO/nrzwV3aoHiliNWgk IXfER4uBo5VGylvqLQeh36nGh5U2i9MD/E3a2zvpcXlPrkns9npsg5uaPx7u96RtbMj0 D1zg== X-Gm-Message-State: AOPr4FWFD/lNQya1FoxaCMDEDioo4Arz0fUVZcbEXbDOXxmM77IDwk2/Qf1ztyUFbotcqQ== X-Received: by 10.55.17.153 with SMTP id 25mr26829115qkr.18.1460851117770; Sat, 16 Apr 2016 16:58:37 -0700 (PDT) Received: from localhost.localdomain (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id f143sm4315534qhf.27.2016.04.16.16.58.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 16 Apr 2016 16:58:36 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix PR c++/27100 Date: Sat, 16 Apr 2016 19:58:31 -0400 Message-Id: <1460851111-24789-1-git-send-email-patrick@parcs.ath.cx> The problem here is that duplicate_decls doesn't preserve the DECL_PENDING_INLINE_P flag of the old decl in the new decl. This happens only when a friend function is defined inside a class and then redeclared. The initial definition sets the DECL_PENDING_INLINE_P flag, but the subsequent redeclaration doesn't retain the flag. This patch makes duplicate_decls retain the DECL_PENDING_INLINE_P flag from the old decl to the new decl. Bootstrapped + regtested on x86_64-pc-linux-gnu. Does this look OK to commit? gcc/cp/ChangeLog: PR c++/27100 * decl.c (duplicate_decls): Properly copy the DECL_PENDING_INLINE_P, DECL_PENDING_INLINE_INFO and DECL_SAVED_FUNCTION_DATA fields from OLDDECL to NEWDECL. gcc/testsuite/ChangeLog: PR c++/27100 * g++.dg/other/friend6.C: New test. --- gcc/cp/decl.c | 13 +++++++++++-- gcc/testsuite/g++.dg/other/friend6.C | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/friend6.C diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c1ad52f..4f79c71 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2375,8 +2375,17 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) } else { - if (DECL_PENDING_INLINE_INFO (newdecl) == 0) - DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); + if (DECL_PENDING_INLINE_P (olddecl)) + { + DECL_PENDING_INLINE_P (newdecl) = 1; + DECL_PENDING_INLINE_INFO (newdecl) + = DECL_PENDING_INLINE_INFO (olddecl); + } + else if (DECL_PENDING_INLINE_P (newdecl)) + ; + else if (DECL_SAVED_FUNCTION_DATA (newdecl) == NULL) + DECL_SAVED_FUNCTION_DATA (newdecl) + = DECL_SAVED_FUNCTION_DATA (olddecl); DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl); diff --git a/gcc/testsuite/g++.dg/other/friend6.C b/gcc/testsuite/g++.dg/other/friend6.C new file mode 100644 index 0000000..5f593a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/friend6.C @@ -0,0 +1,15 @@ +// PR c++/27100 +// This used to fail at link time with an "undefined reference to 'foo'" error. +// { dg-do link } + +struct A +{ + friend void foo (const A&) { } + friend void foo (const A&); +}; + +int +main () +{ + foo (A ()); +}