1 /*============================================================================= 2 Copyright (c) 2004 Joao Abecasis 3 http://spirit.sourceforge.net/ 4 5 Use, modification and distribution is subject to the Boost Software 6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 http://www.boost.org/LICENSE_1_0.txt) 8 =============================================================================*/ 9 10 // This test requires NDEBUG to be undefined, because it depends on 11 // BOOST_SPIRIT_ASSERT throwing an exception. 12 #ifdef NDEBUG 13 # undef NDEBUG 14 #endif 15 16 #include <boost/config.hpp> 17 #include <stdexcept> 18 19 #define BOOST_SPIRIT_ASSERT_EXCEPTION ::spirit_exception 20 21 struct spirit_exception : std::exception 22 { spirit_exceptionspirit_exception23 spirit_exception(char const * msg) 24 : message(msg) 25 { 26 } ~spirit_exceptionspirit_exception27 ~spirit_exception() BOOST_NOEXCEPT_OR_NOTHROW {} 28 whatspirit_exception29 char const* what() const BOOST_NOEXCEPT_OR_NOTHROW { return message; } 30 31 char const * message; 32 }; 33 34 #include <boost/spirit/include/classic_scanner.hpp> 35 #include <boost/spirit/home/classic/symbols/impl/tst.ipp> 36 #include <boost/utility/addressof.hpp> 37 38 #include <boost/detail/lightweight_test.hpp> 39 40 typedef char char_type; 41 typedef char const * iterator; 42 43 char_type data_[] = "whatever"; 44 45 iterator begin = data_; 46 iterator end = data_ 47 + sizeof(data_)/sizeof(char_type); // Yes, this is an intentional bug ;) 48 49 char_type data2_[] = "\0something"; 50 iterator begin2 = data2_; 51 iterator end2 = data2_ + sizeof(data2_)/sizeof(char_type) - 1; 52 main()53int main() 54 { 55 typedef BOOST_SPIRIT_CLASSIC_NS::impl::tst<void *, char_type> symbols; 56 57 symbols symbols_; 58 59 try 60 { 61 // It is not ok to add strings containing the null character. 62 symbols_.add(begin, end, (void*) boost::addressof(symbols_)); 63 BOOST_TEST(0); 64 } 65 catch (spirit_exception &/*e*/) 66 { 67 } 68 69 try 70 { 71 // It is not ok to add strings containing the null character. 72 symbols_.add(begin2, end2, (void*) boost::addressof(symbols_)); 73 BOOST_TEST(0); 74 } 75 catch (spirit_exception &/*e*/) 76 { 77 } 78 return boost::report_errors(); 79 } 80