diff --git a/include/boost/compute/program.hpp b/include/boost/compute/program.hpp index 526ca2b1..218d840a 100644 --- a/include/boost/compute/program.hpp +++ b/include/boost/compute/program.hpp @@ -394,6 +394,10 @@ public: // open file stream std::ifstream stream(file.c_str()); + if(stream.fail()){ + BOOST_THROW_EXCEPTION(std::ios_base::failure("failed to create stream.")); + } + // read source std::string source( (std::istreambuf_iterator(stream)), diff --git a/test/test_program.cpp b/test/test_program.cpp index 2b004ee9..9240293c 100644 --- a/test/test_program.cpp +++ b/test/test_program.cpp @@ -55,6 +55,16 @@ BOOST_AUTO_TEST_CASE(program_source) BOOST_CHECK_EQUAL(std::string(source), program.source()); } +BOOST_AUTO_TEST_CASE(program_source_no_file) +{ + // create program from a non-existant source file + // and verifies it throws. + BOOST_CHECK_THROW(boost::compute::program program = + boost::compute::program::create_with_source + (std::string(), context), + std::ios_base::failure); +} + BOOST_AUTO_TEST_CASE(create_kernel) { boost::compute::program program =