This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: trunk gold not building unoptimized, powerpc.cc refs to invalid_address and pltresolve_size


On Thu, Dec 6, 2012 at 4:29 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Dec 06, 2012 at 03:45:22PM -0800, Ian Lance Taylor wrote:
>> Alan needs to add a definition for the constant.  In C++98, all
>> constants declared in classes, even those declared in template
>> classes, require an explicit definition.
>>
>> template<int size, bool big_endian>
>> const Address Target_powerpc::invalid_address;
>
> How is it that this
>
> template<int size, bool big_endian>
> class Target_powerpc : public Sized_target<size, big_endian>
> {
>  public:
>   typedef
>     Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
>   typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
>   typedef typename elfcpp::Elf_types<size>::Elf_Swxword Signed_address;
>   static const Address invalid_address = static_cast<Address>(0) - 1;
>
> gives no errors about "invalid_address" being undefined, while this
>
> template<int size, bool big_endian>
> class Stub_table : public Output_relaxed_input_section
> {
>  public:
>   typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
>   static const Address invalid_address = static_cast<Address>(0) - 1;
>
> does?

What you've got there is a declaration of the const, just as though
you wrote "extern int i;".  In C++98 you are required to also have a
definition of the const, the equivalent of "int i;".  But the compiler
is not required to diagnose the absence of the definition.  So in
effect what happens is that if the const can be inlined everywhere it
is needed, the compiler won't complain.  But if the compiler happens
to not inline it, then it will complain.  Historically g++ has failed
to inline the const when it is used in a ?: expression, and in a few
other cases as well.  So it is simply that one of the cases above is
being used in a way that requires the definition, when not optimizing.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]