PATCH RFC: PR 33094: Test DECL_INITIAL in make_rtl_for_nonlocal_decl

Jason Merrill
Fri Sep 28 21:49:00 GMT 2007

Mark Mitchell wrote:
> Ian Lance Taylor wrote:
>> namespace
>> {
>> template <typename T>
>> 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<int>::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.)

Yes.  But this happens regardless of whether DECL_EXTERNAL is set.  You 
really can't rely on DECL_EXTERNAL to tell you whether or not something 
is defined; for functions we use DECL_INITAL, for static member 
variables we use DECL_IN_AGGR_P.  constrain_visibility is doing the same 
sort of thing that mark_definable and grokfndecl already did, setting 
DECL_NOT_REALLY_EXTERN not because we have seen a definition, but 
because we've decided that we'd like to write this decl out if we can.

DECL_EXTERNAL doesn't indicate whether or not something is defined, it 
indicates whether or not we need to call assemble_external when we see a 
reference to it.

DECL_NOT_REALLY_EXTERN also doesn't indicate whether or not something is 
defined, it indicates whether or not we should emit it if we have a 
definition and it is needed.

I'm not arguing that this is a sensible design, but that's how the 
compiler already works.  It's simple enough to make the variable in this 
testcase have DECL_EXTERNAL again as you expect, but it's not clear to 
me that this buys us anything.  Do you want to try harder to not set 
DECL_NOT_REALLY_EXTERN in cases where we don't have a definition?


More information about the Gcc-patches mailing list