https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> --- Template argument deduction requires substituting the template arguments where they appear. If that is in the return type, it gets substituted into the return type. If that causes a substitution error then deduction fails (that is how using enable_if on the return type works, it *must* consider the return type during argument deduction for that to work!). If it causes an error outside the immediate context you get an error, not deduction failure (14.8.2 p8).