summaryrefslogtreecommitdiff
path: root/boost/spirit/home/x3/core/parser.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/spirit/home/x3/core/parser.hpp')
-rw-r--r--boost/spirit/home/x3/core/parser.hpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/boost/spirit/home/x3/core/parser.hpp b/boost/spirit/home/x3/core/parser.hpp
index 0df69304e0..27115b8de4 100644
--- a/boost/spirit/home/x3/core/parser.hpp
+++ b/boost/spirit/home/x3/core/parser.hpp
@@ -18,6 +18,8 @@
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/support/traits/has_attribute.hpp>
#include <boost/spirit/home/x3/support/utility/sfinae.hpp>
+#include <boost/core/ignore_unused.hpp>
+#include <boost/assert.hpp>
#include <string>
#if !defined(BOOST_SPIRIT_X3_NO_RTTI)
@@ -63,6 +65,23 @@ namespace boost { namespace spirit { namespace x3
}
};
+ namespace detail {
+ template <typename Parser>
+ static void assert_initialized_rule(Parser const& p) {
+ boost::ignore_unused(p);
+
+ // Assert that we are not copying an unitialized static rule. If
+ // the static is in another TU, it may be initialized after we copy
+ // it. If so, its name member will be nullptr.
+ //
+ // Rather than hardcoding behaviour for rule-type subject parsers,
+ // we simply allow get_info<> to do the check in debug builds.
+#ifndef NDEBUG
+ what(p); // note: allows get_info<> to diagnose the issue
+#endif
+ }
+ }
+
struct unary_category;
struct binary_category;
@@ -74,7 +93,7 @@ namespace boost { namespace spirit { namespace x3
static bool const has_action = Subject::has_action;
unary_parser(Subject const& subject)
- : subject(subject) {}
+ : subject(subject) { detail::assert_initialized_rule(subject); }
unary_parser const& get_unary() const { return *this; }
@@ -91,7 +110,11 @@ namespace boost { namespace spirit { namespace x3
left_type::has_action || right_type::has_action;
binary_parser(Left const& left, Right const& right)
- : left(left), right(right) {}
+ : left(left), right(right)
+ {
+ detail::assert_initialized_rule(left);
+ detail::assert_initialized_rule(right);
+ }
binary_parser const& get_binary() const { return *this; }