From 0a2d7fa0e119cf9202d2d666eceef883df39529d Mon Sep 17 00:00:00 2001 From: Alex Olivas Date: Wed, 18 Nov 2015 16:27:19 -0700 Subject: [PATCH] if the ifstream can't be created in program::create_with_source_file then it throws std::ios_base::failure. --- include/boost/compute/program.hpp | 4 ++++ test/test_program.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) 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 =