Re: possible bug in g++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 15 February 2012 22:17, Mattia Jona-Lasinio wrote:
> Hi Jonathan,
>
> I don´t think this link applies. It is clear that linking will fail in
> the link examples because the static variables are declared but never
> defined,

Right, just like your code.

> i.e. they are never instantiated.

No, it's not to do with instantiation.

It's the same problem, your program is invalid and can be fixed by
adding definitions of the variables.

> On the other hand the difference between the non working versions
>
> std::cout << (b = aa< X<4> >(3))[1].v << std::endl;

The operator<< overload used here takes its argument by reference.
Binding a reference to an object requires the object to have an
address, so you need to provide a definition.

Read the FAQ more carefully.  Your program is invalid. The compiler is
not required to issue a diagnostic, so it *might* accept it, as in
your final example, but that doesn't mean the code is correct. The
code is still wrong.

You can fix it by adding a definition:

template<int T> const int X<T>::v;



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux