Boost logo

Boost Users :

Subject: [Boost-users] [PATCH] Shadow Variables and Unused Globals Cause Warnings/Errors When Headers Are Not in System Path
From: Grant Erickson (gerickson_at_[hidden])
Date: 2009-05-14 17:14:42


I've recently added Boost to an Xcode 3.1.2 project with the following
warnings enabled in GCC/G++ 4.0.1:

    -Werror -Wreturn-type -Wunused-function -Wunused-label -Wunused-variable
    -Wshadow

Unfortunately, when boost is not installed in a "system" path as is the case
here. Unused and shadow variable warnings cause the build to fail when
warnings are treated as errors. This issue last come up for me about a year
ago in 1_35_0 with filesystem.hpp:

http://article.gmane.org/gmane.comp.lib.boost.user/38297/match=shadow+variab
les+cause

The included headers this time are:

    boost/accumulators/accumulators.hpp
    boost/accumulators/statistics/stats.hpp
    boost/accumulators/statistics/rolling_mean.hpp

To test and fix, I isolated with:

    printf "#include <${BoostHeader}>\nint main(void) {
    return 0; }" | /Developer/usr/bin/gcc-4.0 -x c++ -Wall -Wshadow -Werror
    -o test -I${BoostRoot}/boost/include -

The patch to address this is as follows and impacts the headers below:

    boost/accumulators/framework/accumulator_set.hpp
    boost/accumulators/framework/accumulators/droppable_accumulator.hpp
    boost/accumulators/statistics/rolling_mean.hpp
    boost/accumulators/statistics/rolling_window.hpp
    boost/accumulators/statistics_fwd.hpp
    boost/circular_buffer/base.hpp
    boost/circular_buffer/details.hpp
    boost/circular_buffer/space_optimized.hpp
    boost/fusion/container/list/cons.hpp
    boost/fusion/container/list/cons_iterator.hpp
    boost/fusion/container/vector/vector_iterator.hpp
    boost/fusion/view/filter_view/filter_view.hpp
    boost/fusion/view/filter_view/filter_view_iterator.hpp
    boost/fusion/view/iterator_range/iterator_range.hpp
    boost/fusion/view/joint_view/joint_view.hpp
    boost/fusion/view/joint_view/joint_view_iterator.hpp
    boost/fusion/view/single_view/single_view.hpp
    boost/parameter/aux_/arg_list.hpp
    boost/parameter/aux_/maybe.hpp

Because this problem seems to come up frequently, perhaps there is a way
-Wshadow and -Wall can be forced for all unit tests?

Signed-off-by: Grant Erickson <gerickson_at_[hidden]>

---
--- a/boost/accumulators/framework/accumulator_set.hpp    2008-06-20
09:01:50.000000000 -0700
+++ b/boost/accumulators/framework/accumulator_set.hpp    2009-05-14
13:27:51.000000000 -0700
@@ -42,8 +42,8 @@
     template<typename Args>
     struct accumulator_visitor
     {
-        explicit accumulator_visitor(Args const &args)
-          : args(args)
+        explicit accumulator_visitor(Args const &in_args)
+          : args(in_args)
         {
         }
 
--- a/boost/accumulators/framework/accumulators/droppable_accumulator.hpp
2008-06-19 20:47:42.000000000 -0700
+++ b/boost/accumulators/framework/accumulators/droppable_accumulator.hpp
2009-05-14 13:23:19.000000000 -0700
@@ -218,9 +218,9 @@
     private:
         with_cached_result &operator =(with_cached_result const &);
 
-        void set(result_type const &result)
+        void set(result_type const &in_result)
         {
-            ::new(this->cache.address()) result_type(result);
+            ::new(this->cache.address()) result_type(in_result);
         }
 
         result_type const &get() const
--- a/boost/accumulators/statistics/rolling_mean.hpp    2008-12-30
11:30:45.000000000 -0800
+++ b/boost/accumulators/statistics/rolling_mean.hpp    2009-05-14
13:33:12.000000000 -0700
@@ -69,7 +69,7 @@
 //
 namespace extract
 {
-    extractor<tag::rolling_mean> const rolling_mean = {};
+    extern extractor<tag::rolling_mean> const rolling_mean = {};
 }
 
 using extract::rolling_mean;
--- a/boost/accumulators/statistics/rolling_window.hpp    2008-12-30
11:30:45.000000000 -0800
+++ b/boost/accumulators/statistics/rolling_window.hpp    2009-05-14
13:32:57.000000000 -0700
@@ -153,8 +153,8 @@
 //
 namespace extract
 {
-    extractor<tag::rolling_window_plus1> const rolling_window_plus1 = {};
-    extractor<tag::rolling_window> const rolling_window = {};
+    extern extractor<tag::rolling_window_plus1> const rolling_window_plus1
= {};
+    extern extractor<tag::rolling_window> const rolling_window = {};
 }
 
 using extract::rolling_window_plus1;
--- a/boost/accumulators/statistics_fwd.hpp    2008-12-30 11:30:45.000000000
-0800
+++ b/boost/accumulators/statistics_fwd.hpp    2009-05-14 13:31:22.000000000
-0700
@@ -30,7 +30,7 @@
 }
 namespace extract
 {
-    extractor<tag::quantile> const quantile = {};
+    extern extractor<tag::quantile> const quantile = {};
 }
 using extract::quantile;
 
@@ -46,7 +46,7 @@
 }
 namespace extract
 {
-    extractor<tag::tail_mean> const tail_mean = {};
+    extern extractor<tag::tail_mean> const tail_mean = {};
 }
 using extract::tail_mean;
 
--- a/boost/circular_buffer/base.hpp    2008-08-18 01:54:04.000000000 -0700
+++ b/boost/circular_buffer/base.hpp    2009-05-14 13:38:46.000000000 -0700
@@ -1006,9 +1006,9 @@
         \par Complexity
              Constant.
     */
-    explicit circular_buffer(capacity_type capacity, const allocator_type&
alloc = allocator_type())
+    explicit circular_buffer(capacity_type in_capacity, const
allocator_type& alloc = allocator_type())
     : m_size(0), m_alloc(alloc) {
-        initialize_buffer(capacity);
+        initialize_buffer(in_capacity);
         m_first = m_last = m_buff;
     }
 
@@ -1046,13 +1046,13 @@
         \par Complexity
              Linear (in the <code>n</code>).
     */
-    circular_buffer(capacity_type capacity, size_type n, param_value_type
item,
+    circular_buffer(capacity_type in_capacity, size_type n,
param_value_type item,
         const allocator_type& alloc = allocator_type())
     : m_size(n), m_alloc(alloc) {
-        BOOST_CB_ASSERT(capacity >= size()); // check for capacity lower
than size
-        initialize_buffer(capacity, item);
+        BOOST_CB_ASSERT(in_capacity >= size()); // check for capacity lower
than size
+        initialize_buffer(in_capacity, item);
         m_first = m_buff;
-        m_last = capacity == n ? m_buff : m_buff + n;
+        m_last = in_capacity == n ? m_buff : m_buff + n;
     }
 
     //! The copy constructor.
@@ -1145,10 +1145,10 @@
              <a 
href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIte
rator</a>).
     */
     template <class InputIterator>
-    circular_buffer(capacity_type capacity, InputIterator first,
InputIterator last,
+    circular_buffer(capacity_type in_capacity, InputIterator first,
InputIterator last,
         const allocator_type& alloc = allocator_type())
     : m_alloc(alloc) {
-        initialize(capacity, first, last, is_integral<InputIterator>());
+        initialize(in_capacity, first, last, is_integral<InputIterator>());
     }
 
 #endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
@@ -1260,9 +1260,9 @@
             assign(size_type, const_reference)\endlink</code>,
<code>assign(InputIterator, InputIterator)</code>,
             <code>assign(capacity_type, InputIterator,
InputIterator)</code>
     */
-    void assign(capacity_type capacity, size_type n, param_value_type item)
{
-        BOOST_CB_ASSERT(capacity >= n); // check for new capacity lower
than n
-        assign_n(capacity, n, cb_details::assign_n<param_value_type,
allocator_type>(n, item, m_alloc));
+    void assign(capacity_type in_capacity, size_type n, param_value_type
item) {
+        BOOST_CB_ASSERT(in_capacity >= n); // check for new capacity lower
than n
+        assign_n(in_capacity, n, cb_details::assign_n<param_value_type,
allocator_type>(n, item, m_alloc));
     }
 
     //! Assign a copy of the range into the <code>circular_buffer</code>.
@@ -1333,8 +1333,8 @@
             <code>assign(InputIterator, InputIterator)</code>
     */
     template <class InputIterator>
-    void assign(capacity_type capacity, InputIterator first, InputIterator
last) {
-        assign(capacity, first, last, is_integral<InputIterator>());
+    void assign(capacity_type in_capacity, InputIterator first,
InputIterator last) {
+        assign(in_capacity, first, last, is_integral<InputIterator>());
     }
 
     //! Swap the contents of two <code>circular_buffer</code>s.
@@ -2079,14 +2079,14 @@
     }
 
     //! Initialize the internal buffer.
-    void initialize_buffer(capacity_type capacity) {
-        m_buff = allocate(capacity);
-        m_end = m_buff + capacity;
+    void initialize_buffer(capacity_type in_capacity) {
+        m_buff = allocate(in_capacity);
+        m_end = m_buff + in_capacity;
     }
 
     //! Initialize the internal buffer.
-    void initialize_buffer(capacity_type capacity, param_value_type item) {
-        initialize_buffer(capacity);
+    void initialize_buffer(capacity_type in_capacity, param_value_type
item) {
+        initialize_buffer(in_capacity);
         BOOST_TRY {
             cb_details::uninitialized_fill_n_with_alloc(m_buff, size(),
item, m_alloc);
         } BOOST_CATCH(...) {
@@ -2135,35 +2135,35 @@
 
     //! Specialized initialize method.
     template <class IntegralType>
-    void initialize(capacity_type capacity, IntegralType n, IntegralType
item, const true_type&) {
-        BOOST_CB_ASSERT(capacity >= static_cast<size_type>(n)); // check
for capacity lower than n
+    void initialize(capacity_type in_capacity, IntegralType n, IntegralType
item, const true_type&) {
+        BOOST_CB_ASSERT(in_capacity >= static_cast<size_type>(n)); // check
for capacity lower than n
         m_size = static_cast<size_type>(n);
-        initialize_buffer(capacity, item);
+        initialize_buffer(in_capacity, item);
         m_first = m_buff;
-        m_last = capacity == size() ? m_buff : m_buff + size();
+        m_last = in_capacity == size() ? m_buff : m_buff + size();
     }
 
     //! Specialized initialize method.
     template <class Iterator>
-    void initialize(capacity_type capacity, Iterator first, Iterator last,
const false_type&) {
+    void initialize(capacity_type in_capacity, Iterator first, Iterator
last, const false_type&) {
         BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid
iterator type
 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
-        initialize(capacity, first, last,
BOOST_ITERATOR_CATEGORY<Iterator>::type());
+        initialize(in_capacity, first, last,
BOOST_ITERATOR_CATEGORY<Iterator>::type());
 #else
-        initialize(capacity, first, last, BOOST_DEDUCED_TYPENAME
BOOST_ITERATOR_CATEGORY<Iterator>::type());
+        initialize(in_capacity, first, last, BOOST_DEDUCED_TYPENAME
BOOST_ITERATOR_CATEGORY<Iterator>::type());
 #endif
     }
 
     //! Specialized initialize method.
     template <class InputIterator>
-    void initialize(capacity_type capacity,
+    void initialize(capacity_type in_capacity,
         InputIterator first,
         InputIterator last,
         const std::input_iterator_tag&) {
-        initialize_buffer(capacity);
+        initialize_buffer(in_capacity);
         m_first = m_last = m_buff;
         m_size = 0;
-        if (capacity == 0)
+        if (in_capacity == 0)
             return;
         while (first != last && !full()) {
             m_alloc.construct(m_last, *first++);
@@ -2179,32 +2179,32 @@
 
     //! Specialized initialize method.
     template <class ForwardIterator>
-    void initialize(capacity_type capacity,
+    void initialize(capacity_type in_capacity,
         ForwardIterator first,
         ForwardIterator last,
         const std::forward_iterator_tag&) {
         BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for
wrong range
-        initialize(capacity, first, last, std::distance(first, last));
+        initialize(in_capacity, first, last, std::distance(first, last));
     }
 
     //! Initialize the circular buffer.
     template <class ForwardIterator>
-    void initialize(capacity_type capacity,
+    void initialize(capacity_type in_capacity,
         ForwardIterator first,
         ForwardIterator last,
         size_type distance) {
-        initialize_buffer(capacity);
+        initialize_buffer(in_capacity);
         m_first = m_buff;
-        if (distance > capacity) {
-            std::advance(first, distance - capacity);
-            m_size = capacity;
+        if (distance > in_capacity) {
+            std::advance(first, distance - in_capacity);
+            m_size = in_capacity;
         } else {
             m_size = distance;
         }
         BOOST_TRY {
             m_last = cb_details::uninitialized_copy_with_alloc(first, last,
m_buff, m_alloc);
         } BOOST_CATCH(...) {
-            deallocate(m_buff, capacity);
+            deallocate(m_buff, in_capacity);
             BOOST_RETHROW
         }
         BOOST_CATCH_END
--- a/boost/circular_buffer/details.hpp    2008-08-20 09:13:07.000000000
-0700
+++ b/boost/circular_buffer/details.hpp    2009-05-14 13:39:23.000000000
-0700
@@ -146,9 +146,9 @@
 public:
 
     //! Constructor.
-    capacity_control(Size capacity, Size min_capacity = 0)
-    : m_capacity(capacity), m_min_capacity(min_capacity) {
-        BOOST_CB_ASSERT(capacity >= min_capacity); // check for capacity
lower than min_capacity
+    capacity_control(Size in_capacity, Size in_min_capacity = 0)
+    : m_capacity(in_capacity), m_min_capacity(in_min_capacity) {
+        BOOST_CB_ASSERT(in_capacity >= in_min_capacity); // check for
capacity lower than min_capacity
     }
 
     // Default copy constructor.
--- a/boost/circular_buffer/space_optimized.hpp    2008-08-18
01:54:04.000000000 -0700
+++ b/boost/circular_buffer/space_optimized.hpp    2009-05-14
13:33:40.000000000 -0700
@@ -1229,8 +1229,8 @@
     }
 
     //! Ensure the reserve for possible growth up.
-    size_type ensure_reserve(size_type new_capacity, size_type size) const
{
-        if (size + new_capacity / 5 >= new_capacity)
+    size_type ensure_reserve(size_type new_capacity, size_type in_size)
const {
+        if (in_size + new_capacity / 5 >= new_capacity)
             new_capacity *= 2; // ensure at least 20% reserve
         if (new_capacity > m_capacity_ctrl)
             return m_capacity_ctrl;
--- a/boost/fusion/container/list/cons.hpp    2007-11-25 10:07:19.000000000
-0800
+++ b/boost/fusion/container/list/cons.hpp    2009-05-14 13:22:20.000000000
-0700
@@ -69,13 +69,13 @@
         cons()
             : car(), cdr() {}
 
-        explicit cons(typename detail::call_param<Car>::type car)
-            : car(car), cdr() {}
+        explicit cons(typename detail::call_param<Car>::type in_car)
+            : car(in_car), cdr() {}
 
         cons(
-            typename detail::call_param<Car>::type car
-          , typename detail::call_param<Cdr>::type cdr)
-            : car(car), cdr(cdr) {}
+            typename detail::call_param<Car>::type in_car
+          , typename detail::call_param<Cdr>::type in_cdr)
+            : car(in_car), cdr(in_cdr) {}
         
         template <typename Car2, typename Cdr2>
         cons(cons<Car2, Cdr2> const& rhs)
--- a/boost/fusion/container/list/cons_iterator.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/container/list/cons_iterator.hpp    2009-05-14
13:21:41.000000000 -0700
@@ -35,8 +35,8 @@
             typename add_const<Cons>::type>
         identity;
         
-        explicit cons_iterator(cons_type& cons)
-            : cons(cons) {}
+        explicit cons_iterator(cons_type& in_cons)
+            : cons(in_cons) {}
 
         cons_type& cons;
     };
--- a/boost/fusion/container/vector/vector_iterator.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/container/vector/vector_iterator.hpp    2009-05-14
13:17:57.000000000 -0700
@@ -36,8 +36,8 @@
         typedef vector_iterator_identity<
             typename add_const<Vector>::type, N> identity;
 
-        vector_iterator(Vector& vec)
-            : vec(vec) {}
+        vector_iterator(Vector& in_vec)
+            : vec(in_vec) {}
         Vector& vec;
     };
 }}
--- a/boost/fusion/view/filter_view/filter_view.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/view/filter_view/filter_view.hpp    2009-05-14
13:27:21.000000000 -0700
@@ -36,8 +36,8 @@
         typedef typename result_of::end<Sequence>::type last_type;
         typedef Pred pred_type;
 
-        filter_view(Sequence& seq)
-            : seq(seq)
+        filter_view(Sequence& in_seq)
+            : seq(in_seq)
         {}
 
         first_type first() const { return fusion::begin(seq); }
--- a/boost/fusion/view/filter_view/filter_view_iterator.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/view/filter_view/filter_view_iterator.hpp    2009-05-14
13:27:03.000000000 -0700
@@ -36,8 +36,8 @@
         typedef last_iter last_type;
         typedef Pred pred_type;
 
-        filter_iterator(First const& first)
-            : first(filter::call(first_converter::call(first))) {}
+        filter_iterator(First const& in_first)
+            : first(filter::call(first_converter::call(in_first))) {}
 
         first_type first;
     };
--- a/boost/fusion/view/iterator_range/iterator_range.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/view/iterator_range/iterator_range.hpp    2009-05-14
13:20:41.000000000 -0700
@@ -36,9 +36,9 @@
 
         typedef typename traits::category_of<begin_type>::type category;
 
-        iterator_range(First const& first, Last const& last)
-            : first(convert_iterator<First>::call(first))
-            , last(convert_iterator<Last>::call(last)) {}
+        iterator_range(First const& in_first, Last const& in_last)
+            : first(convert_iterator<First>::call(in_first))
+            , last(convert_iterator<Last>::call(in_last)) {}
 
         begin_type first;
         end_type last;
--- a/boost/fusion/view/joint_view/joint_view.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/view/joint_view/joint_view.hpp    2009-05-14
13:19:35.000000000 -0700
@@ -40,9 +40,9 @@
         typedef typename result_of::end<Sequence2>::type concat_last_type;
         typedef typename mpl::plus<result_of::size<Sequence1>,
result_of::size<Sequence2> >::type size;
 
-        joint_view(Sequence1& seq1, Sequence2& seq2)
-            : seq1(seq1)
-            , seq2(seq2)
+        joint_view(Sequence1& in_seq1, Sequence2& in_seq2)
+            : seq1(in_seq1)
+            , seq2(in_seq2)
         {}
 
         first_type first() const { return fusion::begin(seq1); }
--- a/boost/fusion/view/joint_view/joint_view_iterator.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/view/joint_view/joint_view_iterator.hpp    2009-05-14
13:18:46.000000000 -0700
@@ -37,9 +37,9 @@
         typedef forward_traversal_tag category;
         BOOST_STATIC_ASSERT((!result_of::equal_to<first_type,
last_type>::value));
 
-        joint_view_iterator(First const& first, Concat const& concat)
-            : first(first_converter::call(first))
-            , concat(concat_converter::call(concat))
+        joint_view_iterator(First const& in_first, Concat const& in_concat)
+            : first(first_converter::call(in_first))
+            , concat(concat_converter::call(in_concat))
         {}
 
         first_type first;
--- a/boost/fusion/view/single_view/single_view.hpp    2007-11-25
10:07:19.000000000 -0800
+++ b/boost/fusion/view/single_view/single_view.hpp    2009-05-14
13:21:08.000000000 -0700
@@ -35,8 +35,8 @@
         single_view()
             : val() {}
 
-        explicit single_view(typename detail::call_param<T>::type val)
-            : val(val) {}
+        explicit single_view(typename detail::call_param<T>::type in_val)
+            : val(in_val) {}
 
         value_type val;
     };
--- a/boost/parameter/aux_/arg_list.hpp    2008-03-22 14:45:55.000000000
-0700
+++ b/boost/parameter/aux_/arg_list.hpp    2009-05-14 13:16:48.000000000
-0700
@@ -211,9 +211,9 @@
     // Create a new list by prepending arg to a copy of tail.  Used
     // when incrementally building this structure with the comma
     // operator.
-    arg_list(TaggedArg arg, Next const& tail)
+    arg_list(TaggedArg in_arg, Next const& tail)
       : Next(tail)
-      , arg(arg)
+      , arg(in_arg)
     {}
 
     // A metafunction class that, given a keyword and a default
--- a/boost/parameter/aux_/maybe.hpp    2008-03-22 14:45:55.000000000 -0700
+++ b/boost/parameter/aux_/maybe.hpp    2009-05-14 13:16:03.000000000 -0700
@@ -33,8 +33,8 @@
         BOOST_DEDUCED_TYPENAME remove_reference<reference>::type
     >::type non_cv_value;
         
-    explicit maybe(T value)
-      : value(value)
+    explicit maybe(T in_value)
+      : value(in_value)
       , constructed(false)
     {}
 
@@ -48,23 +48,23 @@
             this->destroy();
     }
 
-    reference construct(reference value) const
+    reference construct(reference in_value) const
     {
-        return value;
+        return in_value;
     }
 
     template <class U>
-    reference construct2(U const& value) const
+    reference construct2(U const& in_value) const
     {
-        new (m_storage.bytes) non_cv_value(value);
+        new (m_storage.bytes) non_cv_value(in_value);
         constructed = true;
         return *(non_cv_value*)m_storage.bytes;
     }
 
     template <class U>
-    reference construct(U const& value) const
+    reference construct(U const& in_value) const
     {
-        return this->construct2(value);
+        return this->construct2(in_value);
     }
 
     void destroy()
---

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net