bind_rv_sp_test.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*==============================================================================
  2. Copyright (c) 2006 Peter Dimov
  3. Copyright (c) 2005-2010 Joel de Guzman
  4. Copyright (c) 2010 Thomas Heller
  5. Copyright (c) 2015 John Fletcher
  6. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. ==============================================================================*/
  9. #include <boost/config.hpp>
  10. #if defined(BOOST_MSVC)
  11. #pragma warning(disable: 4786) // identifier truncated in debug info
  12. #pragma warning(disable: 4710) // function not inlined
  13. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  14. #pragma warning(disable: 4514) // unreferenced inline removed
  15. #endif
  16. #include <boost/phoenix/core.hpp>
  17. #include <boost/phoenix/bind.hpp>
  18. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  19. #pragma warning(push, 3)
  20. #endif
  21. #include <iostream>
  22. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  23. #pragma warning(pop)
  24. #endif
  25. #include <boost/detail/lightweight_test.hpp>
  26. #include <boost/shared_ptr.hpp>
  27. struct X
  28. {
  29. int v_;
  30. X( int v ): v_( v )
  31. {
  32. }
  33. int f()
  34. {
  35. return v_;
  36. }
  37. };
  38. struct Y
  39. {
  40. boost::shared_ptr<X> f()
  41. {
  42. return boost::shared_ptr<X>( new X( 42 ) );
  43. }
  44. };
  45. int main()
  46. {
  47. using boost::phoenix::bind;
  48. Y y;
  49. // MSVC 10,9 and 8 all give a COMDAT error with the full test.
  50. // This also fails:
  51. //boost::shared_ptr<X> xp = bind( &Y::f, &y )();
  52. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1700)
  53. boost::shared_ptr<X> xp = y.f();
  54. BOOST_TEST( bind( &X::f, xp)() == 42 );
  55. #else
  56. BOOST_TEST( bind( &X::f, bind( &Y::f, &y ) )() == 42 );
  57. #endif
  58. return boost::report_errors();
  59. }