From 0c4e251ebee2d497c958ec509b2ca664c61e4610 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Thu, 26 Feb 2009 02:33:15 +0000 Subject: [PATCH] Supress warnings on gcc and msvc. Fixes #1515 [SVN r51448] --- include/boost/lambda/casts.hpp | 5 +- .../lambda/detail/lambda_functor_base.hpp | 10 +++- .../boost/lambda/detail/lambda_functors.hpp | 8 ++- include/boost/lambda/detail/lambda_traits.hpp | 50 +++++++++++++++++++ .../detail/operator_return_type_traits.hpp | 17 ++++--- .../boost/lambda/detail/suppress_unused.hpp | 27 ++++++++++ include/boost/lambda/switch.hpp | 8 ++- test/constructor_tests.cpp | 8 ++- test/exception_test.cpp | 4 +- test/extending_rt_traits.cpp | 18 +++++-- test/member_pointer_test.cpp | 4 +- test/operator_tests_simple.cpp | 4 ++ 12 files changed, 142 insertions(+), 21 deletions(-) create mode 100644 include/boost/lambda/detail/suppress_unused.hpp diff --git a/include/boost/lambda/casts.hpp b/include/boost/lambda/casts.hpp index a5f6856..29437a8 100644 --- a/include/boost/lambda/casts.hpp +++ b/include/boost/lambda/casts.hpp @@ -14,6 +14,8 @@ #if !defined(BOOST_LAMBDA_CASTS_HPP) #define BOOST_LAMBDA_CASTS_HPP +#include "boost/lambda/detail/suppress_unused.hpp" + #include namespace boost { @@ -64,11 +66,12 @@ public: } }; - // typedid action +// typeid action class typeid_action { public: template static RET apply(Arg1 &a1) { + detail::suppress_unused_variable_warnings(a1); return typeid(a1); } }; diff --git a/include/boost/lambda/detail/lambda_functor_base.hpp b/include/boost/lambda/detail/lambda_functor_base.hpp index 652bdda..6a43c14 100644 --- a/include/boost/lambda/detail/lambda_functor_base.hpp +++ b/include/boost/lambda/detail/lambda_functor_base.hpp @@ -16,6 +16,10 @@ namespace boost { namespace lambda { +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(push) +#pragma warning(disable:4512) //assignment operator could not be generated +#endif // for return type deductions we wrap bound argument to this class, // which fulfils the base class contract for lambda_functors @@ -42,6 +46,10 @@ public: RET call(CALL_FORMAL_ARGS) const { CALL_USE_ARGS; return elem; } }; +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(pop) +#endif + template inline lambda_functor > var(T& t) { return identity(t); } @@ -337,7 +345,7 @@ class lambda_functor_base, Args> { public: // Args args; not needed - explicit lambda_functor_base(const Args& a) {} + explicit lambda_functor_base(const Args& /*a*/) {} template struct sig { typedef typename return_type_N::type type; diff --git a/include/boost/lambda/detail/lambda_functors.hpp b/include/boost/lambda/detail/lambda_functors.hpp index cb6060e..913ccef 100644 --- a/include/boost/lambda/detail/lambda_functors.hpp +++ b/include/boost/lambda/detail/lambda_functors.hpp @@ -105,7 +105,10 @@ typedef const lambda_functor > placeholder3_type; // other lambda_functors. // ------------------------------------------------------------------- - +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(push) +#pragma warning(disable:4512) //assignment operator could not be generated +#endif // -- lambda_functor NONE ------------------------------------------------ template @@ -244,6 +247,9 @@ public: } }; +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(pop) +#endif } // namespace lambda } // namespace boost diff --git a/include/boost/lambda/detail/lambda_traits.hpp b/include/boost/lambda/detail/lambda_traits.hpp index 9a3a9b3..0e683c2 100644 --- a/include/boost/lambda/detail/lambda_traits.hpp +++ b/include/boost/lambda/detail/lambda_traits.hpp @@ -430,6 +430,56 @@ struct bind_traits { typedef const volatile T (&type)[n]; }; +template +struct bind_traits { + typedef R(&type)(); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3, Arg4); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8); +}; + +template +struct bind_traits { + typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9); +}; + template struct bind_traits >{ typedef T& type; diff --git a/include/boost/lambda/detail/operator_return_type_traits.hpp b/include/boost/lambda/detail/operator_return_type_traits.hpp index 4f6a84f..3d3ac96 100644 --- a/include/boost/lambda/detail/operator_return_type_traits.hpp +++ b/include/boost/lambda/detail/operator_return_type_traits.hpp @@ -233,28 +233,31 @@ template struct contentsof_type { // the IF is because the A::reference in the primary template could // be some class type rather than a real reference, hence // we do not want to make it a reference here either - typedef typename detail::IF< + typedef typename boost::remove_reference::type no_reference; + typedef typename detail::IF< is_reference::value, - const typename boost::remove_reference::type &, - const type1 + const no_reference &, + const no_reference >::RET type; }; template struct contentsof_type { typedef typename contentsof_type::type type1; + typedef typename boost::remove_reference::type no_reference; typedef typename detail::IF< is_reference::value, - volatile typename boost::remove_reference::type &, - volatile type1 + volatile no_reference &, + volatile no_reference >::RET type; }; template struct contentsof_type { typedef typename contentsof_type::type type1; + typedef typename boost::remove_reference::type no_reference; typedef typename detail::IF< is_reference::value, - const volatile typename boost::remove_reference::type &, - const volatile type1 + const volatile no_reference &, + const volatile no_reference >::RET type; }; diff --git a/include/boost/lambda/detail/suppress_unused.hpp b/include/boost/lambda/detail/suppress_unused.hpp new file mode 100644 index 0000000..43999f1 --- /dev/null +++ b/include/boost/lambda/detail/suppress_unused.hpp @@ -0,0 +1,27 @@ +// Boost Lambda Library suppress_unused.hpp ----------------------------- +// +// Copyright (C) 2009 Steven Watanabe +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// For more information, see www.boost.org + +// ------------------------------------------------------------ + +#ifndef BOOST_LAMBDA_SUPRESS_UNUSED_HPP +#define BOOST_LAMBDA_SUPRESS_UNUSED_HPP + +namespace boost { +namespace lambda { +namespace detail { + +template +inline void suppress_unused_variable_warnings(const T&) {} + +} +} +} + +#endif diff --git a/include/boost/lambda/switch.hpp b/include/boost/lambda/switch.hpp index a2c3bad..05d02e9 100644 --- a/include/boost/lambda/switch.hpp +++ b/include/boost/lambda/switch.hpp @@ -465,12 +465,18 @@ BOOST_LAMBDA_SWITCH( BOOST_PP_INC(N) ) #define BOOST_LAMBDA_SWITCH_STATEMENT_HELPER(z, N, A) \ BOOST_LAMBDA_SWITCH_STATEMENT(BOOST_PP_INC(N)) - +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4065) +#endif // up to 9 cases supported (counting default:) BOOST_PP_REPEAT_2ND(9,BOOST_LAMBDA_SWITCH_HELPER,FOO) BOOST_PP_REPEAT_2ND(9,BOOST_LAMBDA_SWITCH_STATEMENT_HELPER,FOO) +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } // namespace lambda } // namespace boost diff --git a/test/constructor_tests.cpp b/test/constructor_tests.cpp index 0b77500..73034d1 100644 --- a/test/constructor_tests.cpp +++ b/test/constructor_tests.cpp @@ -24,6 +24,10 @@ #include #include +#ifdef BOOST_MSVC +#pragma warning(disable:4512) +#endif + using namespace boost::lambda; using namespace std; @@ -34,7 +38,7 @@ bool check_tuple(int n, const T& t) } template <> -bool check_tuple(int n, const null_type& ) { return true; } +bool check_tuple(int /*n*/, const null_type& ) { return true; } void constructor_all_lengths() @@ -183,7 +187,7 @@ public: void test_destructor () { char space[sizeof(is_destructor_called)]; - bool flag; + bool flag = false; is_destructor_called* idc = new(space) is_destructor_called(flag); BOOST_CHECK(flag == false); diff --git a/test/exception_test.cpp b/test/exception_test.cpp index 3349fce..ee90666 100644 --- a/test/exception_test.cpp +++ b/test/exception_test.cpp @@ -29,7 +29,7 @@ using namespace boost::lambda; using namespace std; // to prevent unused variables warnings -template void dummy(const T& t) {} +template void dummy(const T&) {} void erroneous_exception_related_lambda_expressions() { @@ -603,7 +603,7 @@ int test_main(int, char *[]) { return_type_matching(); test_empty_catch_blocks(); } - catch (int x) + catch (int) { BOOST_CHECK(false); } diff --git a/test/extending_rt_traits.cpp b/test/extending_rt_traits.cpp index 01335a5..56916ab 100644 --- a/test/extending_rt_traits.cpp +++ b/test/extending_rt_traits.cpp @@ -16,6 +16,7 @@ #include "boost/lambda/bind.hpp" #include "boost/lambda/lambda.hpp" +#include "boost/lambda/detail/suppress_unused.hpp" #include @@ -23,6 +24,8 @@ #include +using boost::lambda::detail::suppress_unused_variable_warnings; + class A {}; class B {}; @@ -81,7 +84,7 @@ struct plain_return_type_1, A> { } // lambda } // boost -void ok(B b) {} +void ok(B /*b*/) {} void test_unary_operators() { @@ -127,7 +130,7 @@ class my_vector {}; template my_vector, A&, B&>::type> -operator+(const my_vector& a, const my_vector& b) +operator+(const my_vector& /*a*/, const my_vector& /*b*/) { typedef typename return_type_2, A&, B&>::type res_type; @@ -175,8 +178,8 @@ Z operator^=( X&, const Y&) { return Z(); } // assignment class Assign { public: - void operator=(const Assign& a) {} - X operator[](const int& i) { return X(); } + void operator=(const Assign& /*a*/) {} + X operator[](const int& /*i*/) { return X(); } }; @@ -329,9 +332,16 @@ void test_binary_operators() { XX dummy3 = (_1 * _2)(vxx, vyy); VV dummy4 = (_1 * _2)(cvxx, cvyy); + suppress_unused_variable_warnings(dummy1); + suppress_unused_variable_warnings(dummy2); + suppress_unused_variable_warnings(dummy3); + suppress_unused_variable_warnings(dummy4); + my_vector v1; my_vector v2; my_vector d = (_1 + _2)(v1, v2); + suppress_unused_variable_warnings(d); + // bitwise (_1 << _2)(x, y); diff --git a/test/member_pointer_test.cpp b/test/member_pointer_test.cpp index 802e991..e8121d5 100644 --- a/test/member_pointer_test.cpp +++ b/test/member_pointer_test.cpp @@ -118,11 +118,11 @@ class C {}; class D {}; // ->* can be overloaded to do anything -bool operator->*(A a, B b) { +bool operator->*(A /*a*/, B /*b*/) { return false; } -bool operator->*(B b, A a) { +bool operator->*(B /*b*/, A /*a*/) { return true; } diff --git a/test/operator_tests_simple.cpp b/test/operator_tests_simple.cpp index d440fed..78eae51 100644 --- a/test/operator_tests_simple.cpp +++ b/test/operator_tests_simple.cpp @@ -17,6 +17,8 @@ #include "boost/lambda/lambda.hpp" +#include "boost/lambda/detail/suppress_unused.hpp" + #include #include #include @@ -96,6 +98,8 @@ void arithmetic_operators() { // test that unary plus really does something unary_plus_tester u; unary_plus_tester up = (+_1)(u); + + boost::lambda::detail::suppress_unused_variable_warnings(up); } void bitwise_operators() {