Advertisement
homer512

Perfect forwarding error

Jun 18th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <utility>
  2. // using forward
  3. #include <string>
  4.  
  5. namespace {
  6.   struct Foo
  7.   {
  8.     std::string bar;
  9.  
  10.     template<class std_string>
  11.     Foo(std_string&& bar):
  12.       bar(std::forward(bar))
  13.     {}
  14.   };
  15. }
  16. int main()
  17. {
  18.   Foo baz(std::string(" "));
  19.   return 0;
  20. }
  21.  
  22. // clang error:
  23. // forward.cpp:13:11: error: no matching function for call to 'forward'
  24. //       bar(std::forward(bar))
  25. //           ^~~~~~~~~~~~
  26. // forward.cpp:21:7: note: in instantiation of function template specialization '<anonymous namespace>::Foo::Foo<std::basic_string<char> >' requested here
  27. //   Foo baz(std::string(" "));
  28. //       ^
  29. // /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/move.h:62:5: note: candidate template ignored: couldn't infer template argument '_Tp'
  30. //     forward(typename std::remove_reference<_Tp>::type& __t)
  31. //     ^
  32. // /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/move.h:67:5: note: candidate template ignored: couldn't infer template argument '_Tp'
  33. //     forward(typename std::remove_reference<_Tp>::type&& __t)
  34. //     ^
  35. // 1 error generated.
  36.  
  37. // g++ error:
  38. // forward.cpp: In constructor '{anonymous}::Foo::Foo(std_string&&) [with std_string = std::basic_string<char>]':
  39. // forward.cpp:21:27:   instantiated from here
  40. // forward.cpp:13:28: error: no matching function for call to 'forward(std::basic_string<char>&)'
  41. // forward.cpp:13:28: note: candidates are:
  42. // /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/move.h:62:5: note: template<class _Tp> _Tp&& std::forward(typename std::remove_reference<_Tp>::type&)
  43. // /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/move.h:67:5: note: template<class _Tp> _Tp&& std::forward(typename std::remove_reference<_Tp>::type&&)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement