This is the mail archive of the gcc-help@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]

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


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]