Hush my mouth! It wasn't a problem with libstdc++ at all, rather with the parameters being passed to it. VC7 gives 0 div 0 as infinity, while gcc gives NaN. Both seem to me to be valid results, so SubstringFn now accounts for it and the tests pass. Yay.