I think the following code is well-formed and should compile with the
-std=c++0x switch:

   #include <iostream>

   template<typename T>
   struct make { static T&& it(); };

   template<typename R, typename... T>
   struct exists { typedef R type; };

   template< typename Func, typename T >
   void bar(T const& x,
     typename exists<
       int,
       decltype( make<Func>::it()(make<T const&>::it()) ) // SFINAE!
     >::type = 0
   ) {
     std::cout << "bar-1\n";
   }

   template< typename Func >
   void bar(...) {
     std::cout << "bar-2\n";
   }

   int main() {
     bar<void(*)(int&)>(42);
   }

I expect it to compile and print "bar-2". Instead, the compiler rejects the
code with the error

   invalid initialization of reference >int&< with an expression of
   type >const int<.

Cheers!
SG


-- 
           Summary: [C++0x] rejects well-formed code: SFINAE, decltype,
                    function call
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: s dot gesemann at gmail dot com


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

Reply via email to