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

Jens Seidel jensseidel@users.sf.net
Fri Aug 11 09:53:00 GMT 2006


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



More information about the Gcc-help mailing list