Add helper macro - BOOST_ATTRIBUTE_UNUSED - to suppress unused type/variable warnings.

This commit is contained in:
jzmaddock
2014-10-11 13:10:25 +01:00
parent 5838168061
commit 003d33725e
6 changed files with 80 additions and 2 deletions

View File

@ -1152,6 +1152,8 @@ Usage example:
handle_error("ptr is NULL");
``
]]
[[`BOOST_ATTRIBUTE_UNUSED`][Expands to `__attribute__((unused))` when this is available -
can be used to disable compiler warnings relating to unused types or variables.]]
]
[endsect]

View File

@ -205,8 +205,10 @@
# define BOOST_NO_CXX11_FINAL
#endif
// Clang always supports variadic macros
// Clang always supports extern templates
// Unused attribute:
#if defined(__GNUC__) && (__GNUC__ >= 4)
# define BOOST_ATTRIBUTE_UNUSED __attribute__((unused))
#endif
#ifndef BOOST_COMPILER
# define BOOST_COMPILER "Clang version " __clang_version__

View File

@ -235,6 +235,12 @@
# define BOOST_NO_CXX11_REF_QUALIFIERS
#endif
//
// Unused attribute:
#if __GNUC__ >= 4
# define BOOST_ATTRIBUTE_UNUSED __attribute__((unused))
#endif
#ifndef BOOST_COMPILER
# define BOOST_COMPILER "GNU C++ version " __VERSION__
#endif

View File

@ -940,6 +940,13 @@ namespace std{ using ::type_info; }
#define BOOST_CONSTEXPR_OR_CONST constexpr
#endif
//
// Unused variable/typedef workarounds:
//
#ifndef BOOST_ATTRIBUTE_UNUSED
# define BOOST_ATTRIBUTE_UNUSED
#endif
#define BOOST_STATIC_CONSTEXPR static BOOST_CONSTEXPR_OR_CONST
//

View File

@ -89,6 +89,7 @@ test-suite config
[ compile-fail threads/test_thread_fail1.cpp ]
[ compile-fail threads/test_thread_fail2.cpp ]
[ compile boost_fallthrough_test.cpp : [ check-target-builds has_clang_implicit_fallthrough "Clang implicit fallthrough" : <toolset>clang:<cxxflags>"-std=c++11 -Wimplicit-fallthrough" <warnings-as-errors>on <warnings>all ] ]
[ compile helper_macro_test.cpp ]
[ run cstdint_test.cpp : : : <warnings>all <toolset>gcc:<cxxflags>"-Wno-long-long -Wextra" <toolset>darwin:<cxxflags>-Wno-long-long ]
[ run cstdint_test2.cpp : : : <warnings>all <toolset>gcc:<cxxflags>"-Wno-long-long -Wextra" <toolset>darwin:<cxxflags>-Wno-long-long ]
[ compile cstdint_include_test.cpp : <warnings>all <toolset>gcc:<cxxflags>-Wextra ]

View File

@ -0,0 +1,60 @@
// Use, modification and distribution are subject to 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)
#include <boost/config.hpp>
int test_fallthrough(int n)
{
switch (n)
{
case 0:
n++;
BOOST_FALLTHROUGH;
case 1:
n++;
break;
}
return n;
}
int test_unreachable(int i)
{
if(BOOST_LIKELY(i)) return i;
throw i;
BOOST_UNREACHABLE_RETURN(0);
}
BOOST_FORCEINLINE int always_inline(int i){ return ++i; }
BOOST_NOINLINE int never_inline(int i){ return ++i; }
BOOST_NORETURN void always_throw()
{
throw 0;
}
#define test_fallthrough(x) foobar(x)
int main()
{
typedef int unused_type BOOST_ATTRIBUTE_UNUSED;
try
{
int result = test_fallthrough BOOST_PREVENT_MACRO_SUBSTITUTION(0);
BOOST_STATIC_CONSTANT(bool, value = 0);
result += test_unreachable(1);
result += always_inline(2);
result += never_inline(3);
if(BOOST_UNLIKELY(!result))
always_throw();
}
catch(int)
{
return 1;
}
return 0;
}