mirror of
https://github.com/boostorg/config.git
synced 2025-07-31 04:47:16 +02:00
Add helper macro - BOOST_ATTRIBUTE_UNUSED - to suppress unused type/variable warnings.
This commit is contained in:
@ -1152,6 +1152,8 @@ Usage example:
|
|||||||
handle_error("ptr is NULL");
|
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]
|
[endsect]
|
||||||
|
@ -205,8 +205,10 @@
|
|||||||
# define BOOST_NO_CXX11_FINAL
|
# define BOOST_NO_CXX11_FINAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Clang always supports variadic macros
|
// Unused attribute:
|
||||||
// Clang always supports extern templates
|
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
# define BOOST_ATTRIBUTE_UNUSED __attribute__((unused))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef BOOST_COMPILER
|
#ifndef BOOST_COMPILER
|
||||||
# define BOOST_COMPILER "Clang version " __clang_version__
|
# define BOOST_COMPILER "Clang version " __clang_version__
|
||||||
|
@ -235,6 +235,12 @@
|
|||||||
# define BOOST_NO_CXX11_REF_QUALIFIERS
|
# define BOOST_NO_CXX11_REF_QUALIFIERS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// Unused attribute:
|
||||||
|
#if __GNUC__ >= 4
|
||||||
|
# define BOOST_ATTRIBUTE_UNUSED __attribute__((unused))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef BOOST_COMPILER
|
#ifndef BOOST_COMPILER
|
||||||
# define BOOST_COMPILER "GNU C++ version " __VERSION__
|
# define BOOST_COMPILER "GNU C++ version " __VERSION__
|
||||||
#endif
|
#endif
|
||||||
|
@ -940,6 +940,13 @@ namespace std{ using ::type_info; }
|
|||||||
#define BOOST_CONSTEXPR_OR_CONST constexpr
|
#define BOOST_CONSTEXPR_OR_CONST constexpr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// Unused variable/typedef workarounds:
|
||||||
|
//
|
||||||
|
#ifndef BOOST_ATTRIBUTE_UNUSED
|
||||||
|
# define BOOST_ATTRIBUTE_UNUSED
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BOOST_STATIC_CONSTEXPR static BOOST_CONSTEXPR_OR_CONST
|
#define BOOST_STATIC_CONSTEXPR static BOOST_CONSTEXPR_OR_CONST
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -89,6 +89,7 @@ test-suite config
|
|||||||
[ compile-fail threads/test_thread_fail1.cpp ]
|
[ compile-fail threads/test_thread_fail1.cpp ]
|
||||||
[ compile-fail threads/test_thread_fail2.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 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_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 ]
|
[ 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 ]
|
[ compile cstdint_include_test.cpp : <warnings>all <toolset>gcc:<cxxflags>-Wextra ]
|
||||||
|
60
test/helper_macro_test.cpp
Normal file
60
test/helper_macro_test.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user