http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51710
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-30 12:53:27 UTC --- I think the code is invalid because the expression decltype(foo(e1,e2)) does not occur in the "immediate context" of the function type It works if you replace enable_if<cond, decltype(expr)> with enable_if_foo<cond, type> where enable_if_foo evaluates decltype(expr) template<bool, typename E1, typename E2> struct enable_if_foo { typedef decltype(foo(std::declval<E1>(), std::declval<E2>())) type; }; template<typename E1, typename E2> struct enable_if_foo<false, E1, E2> { }; /// operator+ is overloaded for E1,E2 satisfying some_condition only template <typename E1, typename E2> inline auto operator+(E1&& e1, E2&& e2) -> typename enable_if_foo< some_condition<E1,E2>::value, // We check condition E1, E2 >::type { return foo(e1, e2); }