This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/56874] New: Argument deduction failure with lambda and default template argument


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

             Bug #: 56874
           Summary: Argument deduction failure with lambda and default
                    template argument
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org
                CC: jason@gcc.gnu.org


I believe the following code, based on the std::function implementation in
libstdc++, should compile:

template<typename T>
T declval();

template<typename T>
struct function
{
  template<typename F, typename = decltype(declval<F&>() ())>
    function(F)
    { }
};

struct V {
  typedef int value_type;
};

template <typename C>
void map(C&, function<typename C::value_type>)
{
}

int main()
{
  V v;
  map(v, []() { });
}


f.cc: In function 'int main()':
f.cc:24:18: error: no matching function for call to 'map(V&,
main()::__lambda0)'
   map(v, []() { });
                  ^
f.cc:24:18: note: candidate is:
f.cc:17:6: note: template<class C> void map(C&, function<typename
C::value_type>)
 void map(C&, function<typename C::value_type>)
      ^
f.cc:17:6: note:   template argument deduction/substitution failed:
f.cc:24:18: note:   'main()::__lambda0' is not derived from 'function<typename
C::value_type>'
   map(v, []() { });
                  ^

This modified version compiles OK, but whether we say function<int> or
function<typename C::value_type> should not affect deduction of F from the
lambda:

template<typename T>
T declval();

template<typename T>
struct function
{
  template<typename F, typename = decltype(declval<F&>() ())>
    function(F)
    { }
};

struct V {
  typedef int value_type;
};

template <typename C>
void map(C&, function<int>)
{
}

int main()
{
  V v;
  map(v, []() { });
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]