boostorg / spirit

Boost.org spirit module
http://boost.org/libs/spirit
394 stars 162 forks source link

boost::get overloads for boost::spirit::x3::variant should at least lack BOOST_NOEXCEPT #753

Open blashyrkh-ravendark opened 1 year ago

blashyrkh-ravendark commented 1 year ago

Since boost::get may throw boost::bad_get (in the event of a failed application on the given arg), all boost::get overloads for refs or ptrs to boost::spirit::x3::variant objects in boost/spirit/home/x3/support/ast/variant.hpp should at least lack BOOST_NOEXCEPT (which leads to std::terminate invocation when a function indeed throws).

Example:

#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <iostream>

namespace x3 = boost::spirit::x3;

int main()
{
    x3::variant<bool, int> variant {5}; // Program crash
    // boost::variant<bool, int> variant {5}; // No issue

    try {
        const auto v = boost::get<bool>(variant);
    } catch(const boost::bad_get& e) {
        std::cerr << "boost bad_get: " << e.what() << std::endl;
        return 1;
    } catch(const std::exception& e) {
        std::cerr << "std exception: " << e.what() << std::endl;
        return 1;
    } catch(...) {
        std::cerr << "Unknown error";
        return 1;
    }

    return 0;
}