error: explicit template specialization cannot have a storage class

gcc43を使ってみたら怒られたのでメモ:

Explicit template specialization cannot have a storage class

Specializations of templates cannot explicitly specify a storage class, and have the same storage as the primary template. This is a change from previous behavior, based on the feedback and commentary as part of the ISO C++ Core Defect Report 605.

template<typename T>
  static void foo();

template<>
  static void foo<void>();  

Gives:

error: explicit template specialization cannot have a storage class

This also happens with the extern specifier. Fixing this is easy: just remove any storage specifier on the specialization. Like so:

template<typename T>
  static void foo();

template<>
  void foo<void>();  

ということで,特殊化したテンプレートは,特殊化されたテンプレートで宣言されたものと同じstorage classになる(“the same storage as the primary template”の訳のつもり)そうです.だから特殊化の宣言,定義時に指定できないのかな?

ちなみにstorage classについては調べてないけど,たぶんstatic宣言とかauto宣言とかのオブジェクト(もしくはコード?正しくは何て呼ぶんだろう?どなたか教えて下さいm(_ _)m)の配置やリンクに関することだと思われる.

これに対応するだけでコンパイルが通ったので,今後はgcc43にしようかなぁ…