diff --git a/lib/include/aocpp/Generator.hpp b/lib/include/aocpp/Generator.hpp index ed530c1..14e9eb3 100644 --- a/lib/include/aocpp/Generator.hpp +++ b/lib/include/aocpp/Generator.hpp @@ -1,6 +1,7 @@ #ifndef AOCPP_GENERATOR_HPP_ #define AOCPP_GENERATOR_HPP_ +#include #include #include #include @@ -35,7 +36,7 @@ public: { return Generator{handle_type::from_promise(*this)}; } - co::suspend_always initial_suspend() { return {}; } + co::suspend_always initial_suspend() noexcept { return {}; } co::suspend_always final_suspend() noexcept { return {}; } void unhandled_exception() { exception_ = std::current_exception(); } @@ -50,10 +51,10 @@ public: public: Generator() noexcept = default; - Generator(handle_type h) : h_(h) {} - Generator(Generator && g) : h_{g.h_} { g.h_ = nullptr; }; - Generator(Generator const& g) = delete; + Generator(handle_type h) noexcept : h_(h) {} + Generator(Generator && g) noexcept : h_{std::move(g.h_)} { g.h_ = nullptr; }; Generator & operator=(Generator && rhs) = delete; + Generator(Generator const& g) = delete; Generator & operator=(Generator const& rhs) = delete; ~Generator() { if (h_) h_.destroy(); } std::optional operator()() diff --git a/lib/src/Startup.cpp b/lib/src/Startup.cpp index 1381fa2..b27664a 100644 --- a/lib/src/Startup.cpp +++ b/lib/src/Startup.cpp @@ -96,30 +96,46 @@ auto main(int argc, char **argv) -> int if (options.run_tests) { - return doctest::Context{argc, argv}.run(); + try + { + return doctest::Context{argc, argv}.run(); + } + catch (std::exception const &e) + { + std::cerr << "Test suite failed: " << e.what() << std::endl; + return EXIT_FAILURE; + } } - // Establish input streams std::ifstream fin; std::ofstream fout; - std::istream &in{options.in_name ? fin = std::ifstream{options.in_name} : std::cin}; - std::ostream &out{options.out_name ? fout = std::ofstream{options.out_name} : std::cout}; + std::istream *in; + std::ostream *out; - if (in.fail()) + try { + in = &(options.in_name ? fin = std::ifstream{options.in_name} : std::cin); + out = &(options.out_name ? fout = std::ofstream{options.out_name} : std::cout); + } + catch (std::exception const &e) + { + std::cerr << "IO setup failed: " << e.what() << std::endl; + return EXIT_FAILURE; + } + + if (in->fail()) { std::cerr << "Bad input file" << std::endl; return EXIT_FAILURE; } - if (out.fail()) - { + if (out->fail()) { std::cerr << "Bad output file" << std::endl; return EXIT_FAILURE; } try { - Main(in, out); + Main(*in, *out); return EXIT_SUCCESS; } catch (std::exception const &e)