This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: [PATCH] C++ math constants


On 03/01/2013 05:15 AM, Ulrich Drepper wrote:
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?

You don't need an explicit instantiation, just a regular templated definition. This example shows that a definition is needed, and how one is provided.


template <class T>
struct a {
  static constexpr T m = T(1);
};

template <class T>
constexpr T a<T>::m;

const int *
f()
{
  return &a<int>::m;
}

int
main()
{
  return f() == 0;
}

--
Florian Weimer / Red Hat Product Security Team


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