goto_error.cpp 825 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #include <boost/config.hpp>
  7. #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
  8. # error "variadic macros required"
  9. #else
  10. #include <boost/local_function.hpp>
  11. //[goto_error
  12. int error(int x, int y) {
  13. int BOOST_LOCAL_FUNCTION(int z) {
  14. if(z <= 0) goto failure; // Error: Cannot jump to enclosing scope.
  15. else goto success; // OK: Can jump within local function.
  16. success:
  17. return 0;
  18. } BOOST_LOCAL_FUNCTION_NAME(validate)
  19. return validate(x + y);
  20. failure:
  21. return -1;
  22. }
  23. //]
  24. int main(void) {
  25. error(1, 2);
  26. return 0;
  27. }
  28. #endif