Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57386 - in trunk: boost/wave/util libs/wave
From: hartmut.kaiser_at_[hidden]
Date: 2009-11-04 17:45:16


Author: hkaiser
Date: 2009-11-04 17:45:16 EST (Wed, 04 Nov 2009)
New Revision: 57386
URL: http://svn.boost.org/trac/boost/changeset/57386

Log:
Wave: eliminating some of the strict aliasing warnings generated by gcc
Text files modified:
   trunk/boost/wave/util/flex_string.hpp | 104 +++++++++++++++++++--------------------
   trunk/boost/wave/util/pattern_parser.hpp | 20 +++---
   trunk/libs/wave/ChangeLog | 2
   3 files changed, 62 insertions(+), 64 deletions(-)

Modified: trunk/boost/wave/util/flex_string.hpp
==============================================================================
--- trunk/boost/wave/util/flex_string.hpp (original)
+++ trunk/boost/wave/util/flex_string.hpp 2009-11-04 17:45:16 EST (Wed, 04 Nov 2009)
@@ -325,7 +325,7 @@
         E buffer_[1];
     };
     static const Data emptyString_;
-
+
     typedef typename A::size_type size_type;
 
 private:
@@ -342,7 +342,7 @@
         {
             // 11-17-2000: comment added:
             // No need to allocate (capacity + 1) to
- // accomodate the terminating 0, because Data already
+ // accommodate the terminating 0, because Data already
             // has one one character in there
             pData_ = static_cast<Data*>(
                 malloc(sizeof(Data) + capacity * sizeof(E)));
@@ -351,34 +351,34 @@
             pData_->pEndOfMem_ = pData_->buffer_ + capacity;
         }
     }
-
+
 private:
     // Warning - this doesn't initialize pData_. Used in reserve()
     SimpleStringStorage()
     { }
-
+
 public:
     typedef E value_type;
     typedef E* iterator;
     typedef const E* const_iterator;
     typedef A allocator_type;
-
+
     SimpleStringStorage(const SimpleStringStorage& rhs)
     {
         const size_type sz = rhs.size();
         Init(sz, sz);
         if (sz) flex_string_details::pod_copy(rhs.begin(), rhs.end(), begin());
     }
-
+
     SimpleStringStorage(const SimpleStringStorage& s,
         flex_string_details::Shallow)
         : pData_(s.pData_)
     {
     }
-
+
     SimpleStringStorage(const A&)
     { pData_ = const_cast<Data*>(&emptyString_); }
-
+
     SimpleStringStorage(const E* s, size_type len, const A&)
     {
         Init(len, len);
@@ -390,7 +390,7 @@
         Init(len, len);
         flex_string_details::pod_fill(begin(), end(), c);
     }
-
+
     SimpleStringStorage& operator=(const SimpleStringStorage& rhs)
     {
         const size_type sz = rhs.size();
@@ -408,16 +408,16 @@
 
     iterator begin()
     { return pData_->buffer_; }
-
+
     const_iterator begin() const
     { return pData_->buffer_; }
-
+
     iterator end()
     { return pData_->pEnd_; }
-
+
     const_iterator end() const
     { return pData_->pEnd_; }
-
+
     size_type size() const
     { return pData_->pEnd_ - pData_->buffer_; }
 
@@ -479,7 +479,7 @@
         flex_string_details::pod_copy(s, s + sz, end());
         pData_->pEnd_ += sz;
     }
-
+
     template <class InputIterator>
     void append(InputIterator b, InputIterator e)
     {
@@ -527,12 +527,8 @@
 
 template <typename E, class A>
 const typename SimpleStringStorage<E, A>::Data
-SimpleStringStorage<E, A>::emptyString_ = typename SimpleStringStorage<E, A>::Data();
-//{
-// const_cast<E*>(SimpleStringStorage<E, A>::emptyString_.buffer_),
-// const_cast<E*>(SimpleStringStorage<E, A>::emptyString_.buffer_),
-// { E() }
-//};
+SimpleStringStorage<E, A>::emptyString_ =
+ typename SimpleStringStorage<E, A>::Data();
 
 ////////////////////////////////////////////////////////////////////////////////
 // class template AllocatorStringStorage
@@ -584,13 +580,13 @@
             pData_->pEndOfMem_ = pData_->buffer_ + cap;
         }
     }
-
+
 public:
     typedef E value_type;
+ typedef E* iterator;
+ typedef const E* const_iterator;
     typedef A allocator_type;
- typedef typename A::pointer iterator;
- typedef typename A::const_pointer const_iterator;
-
+
     AllocatorStringStorage()
     : A(), pData_(0)
     {
@@ -603,24 +599,24 @@
         Init(sz, sz);
         if (sz) flex_string_details::pod_copy(rhs.begin(), rhs.end(), begin());
     }
-
+
     AllocatorStringStorage(const AllocatorStringStorage& s,
         flex_string_details::Shallow)
     : A(s.get_allocator())
     {
         pData_ = s.pData_;
     }
-
+
     AllocatorStringStorage(const A& a) : A(a)
     {
         pData_ = const_cast<Data*>(
             &SimpleStringStorage<E, A>::emptyString_);
     }
-
+
     AllocatorStringStorage(const E* s, size_type len, const A& a)
     : A(a)
     {
- Init(len, len);
+ Init(len, len);
         flex_string_details::pod_copy(s, s + len, begin());
     }
 
@@ -630,7 +626,7 @@
         Init(len, len);
         flex_string_details::pod_fill(&*begin(), &*end(), c);
     }
-
+
     AllocatorStringStorage& operator=(const AllocatorStringStorage& rhs)
     {
         const size_type sz = rhs.size();
@@ -639,7 +635,7 @@
         pData_->pEnd_ = &*begin() + rhs.size();
         return *this;
     }
-
+
     ~AllocatorStringStorage()
     {
         if (capacity())
@@ -648,19 +644,19 @@
                 sizeof(Data) + capacity() * sizeof(E));
         }
     }
-
+
     iterator begin()
     { return pData_->buffer_; }
     
     const_iterator begin() const
     { return pData_->buffer_; }
-
+
     iterator end()
     { return pData_->pEnd_; }
-
+
     const_iterator end() const
     { return pData_->pEnd_; }
-
+
     size_type size() const
     { return size_type(end() - begin()); }
 
@@ -690,11 +686,11 @@
             // @@@ shrink to fit here
             return;
         }
-
+
         A& myAlloc = *this;
         AllocatorStringStorage newStr(myAlloc);
         newStr.Init(size(), res_arg);
-
+
         flex_string_details::pod_copy(begin(), end(), newStr.begin());
         
         swap(newStr);
@@ -716,14 +712,14 @@
         std::copy(b, e, end());
         pData_->pEnd_ += sz;
     }
-
+
     void swap(AllocatorStringStorage& rhs)
     {
         // @@@ The following line is commented due to a bug in MSVC
         //std::swap(lhsAlloc, rhsAlloc);
         std::swap(pData_, rhs.pData_);
     }
-
+
     const E* c_str() const
     {
         if (pData_ != &SimpleStringStorage<E, A>::emptyString_)
@@ -735,7 +731,7 @@
 
     const E* data() const
     { return &*begin(); }
-
+
     A get_allocator() const
     { return *this; }
 };
@@ -894,26 +890,26 @@
         mutable value_type buf_[maxSmallString + 1];
         Align align_;
     };
-
+
     Storage& GetStorage()
     {
         BOOST_ASSERT(buf_[maxSmallString] == magic);
         Storage* p = reinterpret_cast<Storage*>(&buf_[0]);
         return *p;
     }
-
+
     const Storage& GetStorage() const
     {
         BOOST_ASSERT(buf_[maxSmallString] == magic);
         const Storage *p = reinterpret_cast<const Storage*>(&buf_[0]);
         return *p;
     }
-
+
     bool Small() const
     {
         return buf_[maxSmallString] != magic;
     }
-
+
 public:
   SmallStringOpt(const SmallStringOpt& s)
     {
@@ -930,12 +926,12 @@
         }
         buf_[maxSmallString] = s.buf_[maxSmallString];
     }
-
+
     SmallStringOpt(const allocator_type&)
     {
         buf_[maxSmallString] = maxSmallString;
     }
-
+
     SmallStringOpt(const value_type* s, size_type len, const allocator_type& a)
     {
         if (len <= maxSmallString)
@@ -963,7 +959,7 @@
             buf_[maxSmallString] = magic;
         }
     }
-
+
     SmallStringOpt& operator=(const SmallStringOpt& rhs)
     {
         reserve(rhs.size());
@@ -982,25 +978,25 @@
         if (Small()) return buf_;
         return &*GetStorage().begin();
     }
-
+
     const_iterator begin() const
     {
         if (Small()) return buf_;
         return &*GetStorage().begin();
     }
-
+
     iterator end()
     {
         if (Small()) return buf_ + maxSmallString - buf_[maxSmallString];
         return &*GetStorage().end();
     }
-
+
     const_iterator end() const
     {
         if (Small()) return buf_ + maxSmallString - buf_[maxSmallString];
         return &*GetStorage().end();
     }
-
+
     size_type size() const
     {
         BOOST_ASSERT(!Small() || maxSmallString >= buf_[maxSmallString]);
@@ -1033,7 +1029,7 @@
         }
         BOOST_ASSERT(capacity() >= res_arg);
     }
-
+
     void append(const value_type* s, size_type sz)
     {
         if (!Small())
@@ -1066,7 +1062,7 @@
             }
         }
     }
-
+
     template <class InputIterator>
     void append(InputIterator b, InputIterator e)
     {
@@ -1166,7 +1162,7 @@
             }
         }
     }
-
+
     const value_type* c_str() const
     {
         if (!Small()) return GetStorage().c_str();
@@ -1211,7 +1207,7 @@
     };
 
     Storage& Data() const
- { return *reinterpret_cast<Storage*>(buf_); }
+ { Storage* v= reinterpret_cast<Storage*>(buf_); return *v; }
 
     RefCountType GetRefs() const
     {

Modified: trunk/boost/wave/util/pattern_parser.hpp
==============================================================================
--- trunk/boost/wave/util/pattern_parser.hpp (original)
+++ trunk/boost/wave/util/pattern_parser.hpp 2009-11-04 17:45:16 EST (Wed, 04 Nov 2009)
@@ -31,27 +31,27 @@
     // pattern_and class
     //
     ///////////////////////////////////////////////////////////////////////////
- template <typename CharT = char>
+ template <typename CharT = char, typename Pattern = unsigned long>
     struct pattern_and
       : public boost::spirit::classic::char_parser<pattern_and<CharT> >
     {
- pattern_and(CharT pattern_, unsigned long pattern_mask_ = 0UL)
+ pattern_and(CharT pattern_, Pattern pattern_mask_ = Pattern())
         : pattern(pattern_),
- pattern_mask((0UL != pattern_mask_) ? pattern_mask_ : pattern_)
+ pattern_mask((Pattern() != pattern_mask_) ? pattern_mask_ : Pattern(pattern_))
         {}
 
         template <typename T>
         bool test(T pattern_) const
- { return ((unsigned long)pattern_ & pattern_mask) == (unsigned long)pattern; }
+ { return ((Pattern)pattern_ & pattern_mask) == (Pattern)pattern; }
 
- CharT pattern;
- unsigned long pattern_mask;
+ CharT pattern;
+ Pattern pattern_mask;
     };
 
- template <typename CharT>
- inline pattern_and<CharT>
- pattern_p(CharT pattern, long pattern_mask = 0L)
- { return pattern_and<CharT>(pattern, (unsigned long)pattern_mask); }
+ template <typename CharT, typename Pattern>
+ inline pattern_and<CharT, Pattern>
+ pattern_p(CharT pattern, Pattern pattern_mask = Pattern())
+ { return pattern_and<CharT, Pattern>(pattern, pattern_mask); }
 
 ///////////////////////////////////////////////////////////////////////////////
 } // namespace util

Modified: trunk/libs/wave/ChangeLog
==============================================================================
--- trunk/libs/wave/ChangeLog (original)
+++ trunk/libs/wave/ChangeLog 2009-11-04 17:45:16 EST (Wed, 04 Nov 2009)
@@ -42,6 +42,8 @@
 - Added a new command line option to the wave driver tool: --listguards/-g
   allowing to trace all include files which are either contain a #pragma once
   or contain include guards.
+- Started to elminate g++ struct aliasing warnings (more to fix, mostly in
+ flex_string).
 
 Boost V1.40.0
 - V2.0.2


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