関数のオーバーロードと関数テンプレートの特殊化

#include <iostream>

template<class T>
void f(T t)
{ std::cout << "A" << std::endl; }

template<class T>
void f(T *p)
{ std::cout << "B" << std::endl; }

template<>
void f<>(int *p)
{ std::cout << "C" << std::endl; }

int main()
{
  int i;
  f(&i);
}

「さて,どのfが呼ばれるでしょうか?」と聞かれて「分かりきったこと聞くな.Cが呼ばれるに決まってる」と即答できる人ほど,恐らく下のコードの実行結果に驚くと思われる.

#include <iostream>

template<class T>
void f(T t)
{ std::cout << "A" << std::endl; }

template<>
void f<>(int *p)
{ std::cout << "C" << std::endl; }

template<class T>
void f(T *p)
{ std::cout << "B" << std::endl; }

int main()
{
  int i;
  f(&i);
}

↑さっきのコードでBとCの定義の順番を入れ替えただけ.最初,実行した結果を見て「Σ(゜Д゜;エーッ!」だった自分・・・.でもおかげでもう混乱することはなさそうだ.
Why Not Specialize Function Templates?
規格上の対応条項は↓らへん?

14.8.3 Overload resolution

1 A function template can be overloaded either by (non-template) functions of its name or by (other) function templates of the same name. When a call to that name is written (explicitly, or implicitly using the operator notation), template argument deduction (14.8.2) and checking of any explicit template arguments (14.3) are performed for each function template to find the template argument values (if any) that can be used with that function template to instantiate a function template specialization that can be invoked with the call arguments. For each function template, if the argument deduction and checking succeeds, the templatearguments (deduced and/or explicit) are used to instantiate a single function template specialization which is added to the candidate functions set to be used in overload resolution. If, for a given function template, argument deduction fails, no such function is added to the set of candidate functions for that template. The complete set of candidate functions includes all the function templates instantiated in this way and all of the non-template overloaded functions of the same name. The function template specializations are treated like any other functions in the remainder of overload resolution, except as explicitly noted in 13.3.3.

あと,2番目のコードの挙動はこっちも絡みますよっと.

14.7.3 Explicit specialization

3 A declaration of a function template or class template being explicitly specialized shall be in scope at the point of declaration of an explicit specialization. [Note: a declaration, but not a definition of the template is required. ] The definition of a class or class template shall be in scope at the point of declaration of an explicit specialization for a member template of the class or class template.