Missing error for accessing an invalid type in a template specialisation?

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

 



Hi,

I wrote the following code which compiled fine (using -Wall -W -pedantic):

numeric_constants.h:

template<typename T>
class numeric_constants
{
};

template<>
class numeric_constants<float>
{
  public:
    static float nan() { return m_nan; }
  
  private:
    static const float m_nan;
};

numeric_constants.cpp:

#include "numeric_constants.h"
#include <cmath>

const float numeric_constants<float>::numeric_constants::m_nan = std::sqrt(-1);

Do you see the error? It should probably be

const float numeric_constants<float>::m_nan = std::sqrt(-1);

which compiles also fine with version 4.1.0.

Does anyone know why I do not get an error using the first definition?
Is this a bug in g++?

Please CC: me.

Jens

[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