In your non-compiling example, you're attempting to specialize and define a function that hasn't been declared in the template definition of bar
... In your later example you have actually declared as well as defined the non-specialized version of the function inside the template definition of bar
, which is why it compiles. From what I can tell, here is the associated language in the standard concerning why the first version won't compile (14.7.3/4):
A member function, a member function template, a member class, a member enumeration, a member class template, or a static data member of a class template may be explicitly specialized for a class specialization that is implicitly instantiated; in this case, the definition of the class template shall precede the explicit specialization for the member of the class template