Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57986 - in trunk/boost/spirit/home: karma/nonterminal lex/lexer qi/nonterminal
From: hartmut.kaiser_at_[hidden]
Date: 2009-11-27 17:28:35


Author: hkaiser
Date: 2009-11-27 17:28:35 EST (Fri, 27 Nov 2009)
New Revision: 57986
URL: http://svn.boost.org/trac/boost/changeset/57986

Log:
Spirit: removed UB in rule and token_def initialization, added copy constructor for token_def
Text files modified:
   trunk/boost/spirit/home/karma/nonterminal/rule.hpp | 13 +++++++++++--
   trunk/boost/spirit/home/lex/lexer/token_def.hpp | 27 ++++++++++++++++++---------
   trunk/boost/spirit/home/qi/nonterminal/rule.hpp | 13 +++++++++++--
   3 files changed, 40 insertions(+), 13 deletions(-)

Modified: trunk/boost/spirit/home/karma/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/karma/nonterminal/rule.hpp 2009-11-27 17:28:35 EST (Fri, 27 Nov 2009)
@@ -37,6 +37,11 @@
 #include <boost/spirit/home/karma/nonterminal/detail/generator_binder.hpp>
 #include <boost/spirit/home/karma/nonterminal/detail/parameterized.hpp>
 
+#if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable: 4355) // 'this' : used in base member initializer list warning
+#endif
+
 namespace boost { namespace spirit { namespace karma
 {
     BOOST_PP_REPEAT(SPIRIT_ATTRIBUTES_LIMIT, SPIRIT_USING_ATTRIBUTE, _)
@@ -128,7 +133,7 @@
         function_type;
 
         explicit rule(std::string const& name_ = "unnamed-rule")
- : base_type(terminal::make(alias()))
+ : base_type(terminal::make(reference_(*this)))
           , name_(name_)
         {
         }
@@ -142,7 +147,7 @@
 
         template <typename Expr>
         rule (Expr const& expr, std::string const& name_ = "unnamed-rule")
- : base_type(terminal::make(alias()))
+ : base_type(terminal::make(reference_(*this)))
           , name_(name_)
         {
             // Report invalid expression error as early as possible.
@@ -300,4 +305,8 @@
 
 }}}
 
+#if defined(BOOST_MSVC)
+# pragma warning(pop)
+#endif
+
 #endif

Modified: trunk/boost/spirit/home/lex/lexer/token_def.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/token_def.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/token_def.hpp 2009-11-27 17:28:35 EST (Fri, 27 Nov 2009)
@@ -30,6 +30,11 @@
 #include <string>
 #include <cstdlib>
 
+#if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable: 4355) // 'this' : used in base member initializer list warning
+#endif
+
 namespace boost { namespace spirit { namespace lex
 {
     ///////////////////////////////////////////////////////////////////////////
@@ -53,11 +58,6 @@
         typedef typename proto::terminal<reference_>::type terminal_type;
         typedef proto::extends<terminal_type, token_def> proto_base_type;
 
- reference_ alias() const
- {
- return reference_(*this);
- }
-
     public:
         // Qi interface: metafunction calculating parser return type
         template <typename Context, typename Iterator>
@@ -154,18 +154,23 @@
 
         // Lex interface: constructing token definitions
         token_def()
- : proto_base_type(terminal_type::make(alias()))
+ : proto_base_type(terminal_type::make(reference_(*this)))
           , def_('\0'), token_id_()
- , unique_id_(std::size_t(~0)), token_state_(std::size_t(~0)) {}
+ , unique_id_(std::size_t(~0)), token_state_(std::size_t(~0)) {}
+
+ token_def(token_def const& rhs)
+ : proto_base_type(terminal_type::make(reference_(*this)))
+ , def_(rhs.def_), token_id_(rhs.token_id_)
+ , unique_id_(rhs.unique_id_), token_state_(rhs.token_state_) {}
 
         explicit token_def(char_type def_, Idtype id_ = Idtype())
- : proto_base_type(terminal_type::make(alias()))
+ : proto_base_type(terminal_type::make(reference_(*this)))
           , def_(def_)
           , token_id_(std::size_t(Idtype() == id_ ? def_ : id_))
           , unique_id_(std::size_t(~0)), token_state_(std::size_t(~0)) {}
 
         explicit token_def(string_type const& def_, Idtype id_ = Idtype())
- : proto_base_type(terminal_type::make(alias()))
+ : proto_base_type(terminal_type::make(reference_(*this)))
           , def_(def_), token_id_(id_)
           , unique_id_(std::size_t(~0)), token_state_(std::size_t(~0)) {}
 
@@ -208,4 +213,8 @@
 
 }}}
 
+#if defined(BOOST_MSVC)
+# pragma warning(pop)
+#endif
+
 #endif

Modified: trunk/boost/spirit/home/qi/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/rule.hpp 2009-11-27 17:28:35 EST (Fri, 27 Nov 2009)
@@ -35,6 +35,11 @@
 #include <boost/spirit/home/qi/nonterminal/detail/parameterized.hpp>
 #include <boost/spirit/home/qi/nonterminal/detail/parser_binder.hpp>
 
+#if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable: 4355) // 'this' : used in base member initializer list warning
+#endif
+
 namespace boost { namespace spirit { namespace qi
 {
     BOOST_PP_REPEAT(SPIRIT_ATTRIBUTES_LIMIT, SPIRIT_USING_ATTRIBUTE, _)
@@ -119,7 +124,7 @@
         function_type;
 
         explicit rule(std::string const& name_ = "unnamed-rule")
- : base_type(terminal::make(alias()))
+ : base_type(terminal::make(reference_(*this)))
           , name_(name_)
         {
         }
@@ -133,7 +138,7 @@
 
         template <typename Expr>
         rule (Expr const& expr, std::string const& name_ = "unnamed-rule")
- : base_type(terminal::make(alias()))
+ : base_type(terminal::make(reference_(*this)))
           , name_(name_)
         {
             // Report invalid expression error as early as possible.
@@ -311,4 +316,8 @@
     };
 }}}
 
+#if defined(BOOST_MSVC)
+# pragma warning(pop)
+#endif
+
 #endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk