This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] C++ math constants
- From: Ulrich Drepper <drepper at gmail dot com>
- To: Benjamin De Kosnik <bkoz at redhat dot com>
- Cc: Daniel KrÃgler <daniel dot kruegler at gmail dot com>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 28 Feb 2013 23:15:35 -0500
- Subject: Re: [PATCH] C++ math constants
- References: <CAOPLpQdxQkFcUb6-us3gdzesTwx8MyzxccF_TTZvO3=E0A1xsw@mail.gmail.com> <CAGNvRgAf8oNHAcORU-RapgTWep9fYWcf=Z7d5OvP2zbYstu3dg@mail.gmail.com> <20130221093859.33b4d2fe@oakwood>
On Thu, Feb 21, 2013 at 12:38 PM, Benjamin De Kosnik <bkoz@redhat.com> wrote:
> Not seeing it.
>
> Say for:
>
> #include <iostream>
>
> // A class for math constants.
> template<typename _RealType>
> struct __math_constants
> {
> // Constant @f$ \pi @f$.
> static constexpr _RealType __pie =
> 3.1415926535897932384626433832795029L; };
>
> template<class T>
> void print(const T& t) { std::cout << t; }
>
> int main()
> {
> print(__math_constants<double>::__pie);
> return 0;
> }
>
> I'm not getting any definition, even at -O0.
Even more so: how would an explicit instantiation even work?
Try this simplified code:
template<typename T>
struct a {
static constexpr T m = T(1);
};
If you try
template<> constexpr int a::m<int>;
nothing gets emitted into the object file (this is even with the trunk
gcc). If I use
template<> constexpr int a::m<int> = 1;
I get a definition but I have to remove the initialization in the
class definition itself. If I use
struct template a<int>;
there is no output in the file as well.
All this makes perfect sense with gcc. Since the constant will never
be referenced as a variable there is no need for the compiler to emit
a definition. If the argument is that there has to be one, how would
it be done?