fork(3) download
  1. #include <functional>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. struct Y;
  6.  
  7. struct X
  8. {
  9. std::function<bool(Y&)> b{[] (auto& y_) { return y_.a; }};
  10.  
  11. bool a{false};
  12. };
  13.  
  14. struct Y
  15. {
  16. std::function<bool(X&)> b{[] (auto& x_) { return x_.a; }};
  17.  
  18. bool a{true};
  19. };
  20.  
  21. int main()
  22. {
  23. return 0;
  24. }
  25.  
  26.  
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘X::<lambda(auto:1&)> [with auto:1 = Y]’:
/usr/include/c++/6/type_traits:2481:26:   required by substitution of ‘template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = X::<lambda(auto:1&)>&; _Args = {Y&}]’
/usr/include/c++/6/type_traits:2492:55:   required from ‘struct std::__result_of_impl<false, false, X::<lambda(auto:1&)>&, Y&>’
/usr/include/c++/6/type_traits:2496:12:   required from ‘class std::result_of<X::<lambda(auto:1&)>&(Y&)>’
/usr/include/c++/6/functional:1913:9:   required by substitution of ‘template<class _Functor, class, class> std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = X::<lambda(auto:1&)>; <template-parameter-1-2> = void; <template-parameter-1-3> = <missing>]’
prog.cpp:9:58:   required from here
prog.cpp:9:54: error: invalid use of incomplete type ‘struct Y’
  std::function<bool(Y&)> b{[] (auto& y_) { return y_.a; }};
                                                   ~~~^
prog.cpp:5:8: note: forward declaration of ‘struct Y’
 struct Y;
        ^
prog.cpp:9:58: error: could not convert ‘{<lambda closure object>X::<lambda(auto:1&)>{}}’ from ‘<brace-enclosed initializer list>’ to ‘std::function<bool(Y&)>’
  std::function<bool(Y&)> b{[] (auto& y_) { return y_.a; }};
                                                          ^
stdout
Standard output is empty