http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56283



             Bug #: 56283

           Summary: std::result_of does not gracefully SFINAE (not define

                    ::type)

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: libstdc++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: pot...@mac.com





>From the spec of std::result_of,



If the expression INVOKE(declval<Fn>(), declval<ArgTypes>()...) is well formed

when treated as an unevaluated operand (Clause 5), the member typedef type

shall name the type decltype(INVOKE(declval<Fn>(), declval<ArgTypes>()...));

otherwise, there shall be no member type.



If the given INVOKE expression is invalid, ::type should not exist. But an

attempt to use it this way to detect a valid call fails.



Below is a short demo program. A non-overloaded function name and a functor

type with an overloaded call operator are passed to result_of through a type

traits style SFINAE wrapper. None of the cases work. In 2 of the 3 cases the

failure fires the static assertion, but not for the multiple overload issue.





#include <type_traits>



template< typename fn, typename = void >

struct is_invokable : std::false_type {};



template< typename fn >

struct is_invokable< fn, typename std::conditional< true, void, typename

std::result_of< fn >::type >::type >

        : std::true_type {};



void f( int );

static_assert( ! is_invokable< decltype( f ) &( char const * ) >(), "can

convert c-string to int" );



struct s {

    void operator() ( int ) {}

    void operator() ( float ) {}

};

static_assert( ! is_invokable< s( double ) >(), "resolved ambiguous conversion"

);

static_assert( ! is_invokable< s( char * ) >(), "converted pointer to number"

);

Reply via email to