From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31975 invoked by alias); 18 Aug 2007 00:09:15 -0000 Received: (qmail 31768 invoked by uid 22791); 18 Aug 2007 00:09:09 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 18 Aug 2007 00:09:05 +0000 Received: (qmail 2079 invoked from network); 18 Aug 2007 00:09:03 -0000 Received: from unknown (HELO ?192.168.0.3?) (mitchell@127.0.0.2) by mail.codesourcery.com with ESMTPA; 18 Aug 2007 00:09:03 -0000 Message-ID: <46C63895.9040001@codesourcery.com> Date: Sat, 18 Aug 2007 00:09:00 -0000 From: Mark Mitchell User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Ian Lance Taylor CC: gcc-patches@gcc.gnu.org Subject: Re: PATCH RFC: PR 33094: Test DECL_INITIAL in make_rtl_for_nonlocal_decl References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2007-08/txt/msg01166.txt.bz2 Ian Lance Taylor wrote: > namespace > { > > template > class A > { > virtual T f1() { return c; } > static const T c = 0; > }; Thanks for the analysis! > All those steps seem reasonable. If the anonymous namespace is > removed from the test case, all is well because DECL_EXTERNAL is set. > When using the anonymous namespace, DECL_EXTERNAL is not set. That seems wrong. This declaration is not a definition. For example, a reference to &A::c from within this file should be unresolved at link-time. (The standard says that this is an invalid thing to do; I don't know if it says that a diagnostic is required.) > /* If this static data member is needed, provide it to the > back end. */ > if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl)) > DECL_EXTERNAL (decl) = 0; I think DECL_NOT_REALLY_EXTERN is the wrong test here, now that things with anonymous namespaces get ELF local linkage. The confusion here is that the language says they have external linkage; it's an optimization that, in generating object files, we now give them ELF local linkage. There's no such thing as a "static" forward declaration (e.g., "static int i;" is a definition, not a declaration that "i" exists) -- but now we've essentially created such a thing. I think DECL_EXTERNAL has historically only applied to TREE_PUBLIC things -- but probably that's the best way to represent that. In other words, interpret DECL_EXTERNAL as "there is no definition of this entity in this translation unit (yet)". > The DECL_NOT_REALLY_EXTERN flag is only set when using an anonymous > namespace. It happens in constrain_visibility: I think that's wrong. I think we should leave DECL_NOT_REALLY_EXTERN clear until/unless we actually encounter a definition. I don't think constrain_visibility should have any effect on DECL_NOT_REALLY_EXTERN, given the above. -- Mark Mitchell CodeSourcery mark@codesourcery.com (650) 331-3385 x713