thrust::transform wrong template type deduction

Hi there,

I’m getting a type deduction error from nvcc while trying to do a thrust::transform with a lambda from host code. The error is this one,

/usr/local/cuda-7.5/bin/../targets/x86_64-linux/include/thrust/detail/internal_functional.h:345:21: error: no match for ‘operator=’ (operand types are ‘A’ and ‘int’)
     thrust::get<2>(t) = f(thrust::get<0>(t), thrust::get<1>(t));

The code is as follows, and can be [tried] to compile with CUDA 7.5:

nvcc test.cu -std=c++11 --expt-extended-lambda

#include <cuda_runtime.h>
#include <thrust/execution_policy.h>
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <vector>

struct A {
  __host__ __device__ A () {}
};

int main (void){
  std::vector<A> a (5);
  thrust::device_vector<A> dev_A(a.begin(), a.end());
  thrust::device_vector<A> dev_A2(a.begin(), a.end());

  thrust::transform(thrust::device, dev_A.begin(), dev_A.end(), dev_A2.begin(), dev_A2.begin(),
    [] __device__ (const A& a0, const A& a1) -> A {
      A a2;
      return a2;
    });

  return 0;
}

By digging a little bit, it seems type deduction is trying to interpret the BinaryFunction inside some binary_transform_functor into type __nv_device_lambda_wrapper_t<int (*)(), main, 1u>, which is incorrect (it should be type A). Here’s the first line of type deduction:

/usr/local/cuda-7.5/bin/../targets/x86_64-linux/include/thrust/detail/internal_functional.h: In instantiation of ‘typename thrust::detail::enable_if_non_const_reference_or_tuple_of_iterator_references<typename thrust::tuple_element<2, Tuple>::type>::type thrust::detail::binary_transform_functor<BinaryFunction>::operator()(Tuple) [with Tuple = thrust::detail::tuple_of_iterator_references<A&, A&, A&, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>; BinaryFunction = __nv_device_lambda_wrapper_t<int (*)(), main, 1u>; typename thrust::detail::enable_if_non_const_reference_or_tuple_of_iterator_references<typename thrust::tuple_element<2, Tuple>::type>::type = void]’:
/usr/local/cuda-7.5/bin/../targets/x86_64-linux/include/thrust/detail/function.h:60:65:   required from ‘Result thrust::detail::wrapped_function<Function, Result>::operator()(const Argument&) const [with Argument = thrust::detail::tuple_of_iterator_references<thrust::device_reference<A>, thrust::device_reference<A>, thrust::device_reference<A>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>; Function = thrust::detail::binary_transform_functor<__nv_device_lambda_wrapper_t<int (*)(), main, 1u> >; Result = void]’

Any suggestion on how to do this?

Thanks a lot!