nvcc fails to preprocess c++11 <functional> code

Nvcc fails to preprocess c++11 functional code (std::function, std::bind etc.). The code is just some host-only templates included in .cu files. It is compiled successfully by g++ alone, however compilation fails after nvcc preprocessing.

Sample code:

#include <iostream>                                                             
#include <functional>                                                           
void foo(int a, int b, int c)                                                   
  std::cout << a << " " << b << " " << c << std::endl;                          
void bar(std::function<void(int, int)> fun)                                     
  fun(1, 2);                                                                    
int main()                                                                      
  bar(std::bind(&foo, 1, std::placeholders::_1, std::placeholders::_2));        
  return 0;                                                                     

g+±6 -std=c++14 foo.cpp -o foo # Successful
nvcc -std=c++14 foo.cu -o foo # Failed

My environment:
Cuda compilation tools, release 9.1, V9.1.85

I couldn’t find any topic covering the issue. Is it known already? Are there any workarounds?

Workaround: Since this is host-only code, segregate it into a regular .cpp file to be processed by gcc directly, instead going through the code splitting mechanism used by nvcc.

I am not familiar with this aspect of C++11. Is it possible that you are making use of a gcc extension instead of standard C++11? If you are quite convinced that this should compile as ISO C++11, you could always file a bug with NVIDIA (bug reporting form is linked from the registered developer website). You already have a simple repro case in hand.

Thank you! I missed the form.
I am pretty certain this is nvcc bug. I’ve just reported it.

I think the bug is with passing nvcc -std=c++14, nvcc is know to reject this parameter in CUDA 8, so CUDA 9 may not include a fix. Try passing nvcc -std=c++11 if you only need C++11 capability, otherwise manual segregation per njuffa.