From 3596eec09af058a448a4f8b26aede11edf932684 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 9 Dec 2002 12:21:54 +0000 Subject: [PATCH] Added BOOST_UNREACHABLE_RETURN workaround macro. [SVN r16574] --- config.htm | 20 ++++++++++++++++--- include/boost/config/suffix.hpp | 11 +++++++++++ test/Jamfile | 5 ++++- test/config_info.cpp | 2 ++ test/config_test.cpp | 8 +++++++- test/no_ret_det_fail.cpp | 35 +++++++++++++++++++++++++++++++++ test/no_ret_det_pass.cpp | 35 +++++++++++++++++++++++++++++++++ 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 test/no_ret_det_fail.cpp create mode 100644 test/no_ret_det_pass.cpp diff --git a/config.htm b/config.htm index a077f498..34a80360 100644 --- a/config.htm +++ b/config.htm @@ -802,6 +802,14 @@ f(&bar); // should choose #2. The compiler does not support template template parameters. + + BOOST_NO_UNREACHABLE_RETURN_DETECTION + Compiler + If a return is unreachable, then no return statement + should be required, however some compilers insist on it, + while other issue a bunch of warnings if it is in fact + present. + BOOST_NO_USING_TEMPLATE Compiler @@ -904,9 +912,9 @@ present.

BOOST_HAS_NRVO Compiler Indicated that the compiler supports the named return - value optimization (NRVO). Used to select the most efficient - implementation for some function. See - boost/operators.hpp + value optimization (NRVO). Used to select the most + efficient implementation for some function. See boost/operators.hpp for example. @@ -1071,6 +1079,12 @@ provide workarounds for compiler/standard library defects.

}; + + BOOST_UNREACHABLE_RETURN(result) + Normally evaluates to nothing, but evaluates to return x; if the compiler + requires a return, even when it can never be reached. + BOOST_USE_FACET(Type, loc) When the standard library diff --git a/include/boost/config/suffix.hpp b/include/boost/config/suffix.hpp index e38f5d25..6635666b 100644 --- a/include/boost/config/suffix.hpp +++ b/include/boost/config/suffix.hpp @@ -309,6 +309,17 @@ namespace std { # define BOOST_NESTED_TEMPLATE #endif +// BOOST_UNREACHABLE_RETURN(x) workaround -------------------------------------// +// Normally evaluates to nothing, unless BOOST_NO_UNREACHABLE_RETURN_DETECTION +// is defined, in which case it evaluates to return x; Use when you have a return +// statement that can never be reached. + +#ifdef BOOST_NO_UNREACHABLE_RETURN_DETECTION +# define BOOST_UNREACHABLE_RETURN(x) return x; +#else +# define BOOST_UNREACHABLE_RETURN(x) +#endif + // BOOST_DEDUCED_TYPENAME workaround ------------------------------------------// // // Some compilers don't support the use of `typename' for dependent diff --git a/test/Jamfile b/test/Jamfile index 7685e532..5ace0e6d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -1,6 +1,6 @@ # # Regression test Jamfile for boost configuration setup. -# This file was automatically generated on Tue Nov 12 11:07:30 2002, +# This file was automatically generated on Mon Dec 9 12:06:12 2002, # do not edit by hand... # subproject libs/config/test ; @@ -102,6 +102,9 @@ test-suite "BOOST_NO_PRIVATE_IN_AGGREGATE" : test-suite "BOOST_NO_POINTER_TO_MEMBER_CONST" : [ run no_ptr_mem_const_pass.cpp ../../test/build/prg_exec_monitor ] [ link-fail no_ptr_mem_const_fail.cpp ../../test/build/prg_exec_monitor ] ; +test-suite "BOOST_NO_UNREACHABLE_RETURN_DETECTION" : +[ run no_ret_det_pass.cpp ../../test/build/prg_exec_monitor ] +[ link-fail no_ret_det_fail.cpp ../../test/build/prg_exec_monitor ] ; test-suite "BOOST_NO_STRINGSTREAM" : [ run no_sstream_pass.cpp ../../test/build/prg_exec_monitor ] [ link-fail no_sstream_fail.cpp ../../test/build/prg_exec_monitor ] ; diff --git a/test/config_info.cpp b/test/config_info.cpp index 1b867a85..b6be55bd 100644 --- a/test/config_info.cpp +++ b/test/config_info.cpp @@ -915,9 +915,11 @@ void print_boost_macros() PRINT_MACRO(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION); PRINT_MACRO(BOOST_NO_TEMPLATE_TEMPLATES); PRINT_MACRO(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS); + PRINT_MACRO(BOOST_NO_UNREACHABLE_RETURN_DETECTION); PRINT_MACRO(BOOST_NO_USING_TEMPLATE); PRINT_MACRO(BOOST_NO_VOID_RETURNS); PRINT_MACRO(BOOST_STD_EXTENSION_NAMESPACE); + PRINT_MACRO(BOOST_UNREACHABLE_RETURN(0)); } void print_separator() diff --git a/test/config_test.cpp b/test/config_test.cpp index 24e8db59..c65c1eca 100644 --- a/test/config_test.cpp +++ b/test/config_test.cpp @@ -10,7 +10,7 @@ // Do not edit this file, it was generated automatically by // ../tools/generate from boost_*.cxx on -// Tue Nov 12 11:07:30 2002 +// Mon Dec 9 12:06:12 2002 #include #define BOOST_INCLUDE_MAIN @@ -167,6 +167,11 @@ namespace boost_no_private_in_aggregate = empty_boost; #else namespace boost_no_pointer_to_member_const = empty_boost; #endif +#ifndef BOOST_NO_UNREACHABLE_RETURN_DETECTION +#include "boost_no_ret_det.cxx" +#else +namespace boost_no_unreachable_return_detection = empty_boost; +#endif #ifndef BOOST_NO_STRINGSTREAM #include "boost_no_sstream.cxx" #else @@ -413,6 +418,7 @@ int test_main( int, char *[] ) BOOST_TEST(0 == boost_no_std_distance::test()); BOOST_TEST(0 == boost_no_std_allocator::test()); BOOST_TEST(0 == boost_no_stringstream::test()); + BOOST_TEST(0 == boost_no_unreachable_return_detection::test()); BOOST_TEST(0 == boost_no_pointer_to_member_const::test()); BOOST_TEST(0 == boost_no_private_in_aggregate::test()); BOOST_TEST(0 == boost_no_template_partial_specialization::test()); diff --git a/test/no_ret_det_fail.cpp b/test/no_ret_det_fail.cpp new file mode 100644 index 00000000..ad8ef046 --- /dev/null +++ b/test/no_ret_det_fail.cpp @@ -0,0 +1,35 @@ + +// (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Test file for macro BOOST_NO_UNREACHABLE_RETURN_DETECTION +// This file should not compile, if it does then +// BOOST_NO_UNREACHABLE_RETURN_DETECTION need not be defined. +// see boost_no_ret_det.cxx for more details + +// Do not edit this file, it was generated automatically by +// ../tools/generate from boost_no_ret_det.cxx on +// Mon Dec 9 12:06:12 2002 + +// Must not have BOOST_ASSERT_CONFIG set; it defeats +// the objective of this file: +#ifdef BOOST_ASSERT_CONFIG +# undef BOOST_ASSERT_CONFIG +#endif + +#include +#include "test.hpp" + +#ifdef BOOST_NO_UNREACHABLE_RETURN_DETECTION +#include "boost_no_ret_det.cxx" +#else +#error "this file should not compile" +#endif + +int cpp_main( int, char *[] ) +{ + return boost_no_unreachable_return_detection::test(); +} + diff --git a/test/no_ret_det_pass.cpp b/test/no_ret_det_pass.cpp new file mode 100644 index 00000000..01208fec --- /dev/null +++ b/test/no_ret_det_pass.cpp @@ -0,0 +1,35 @@ + +// (C) Copyright Boost.org 1999. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Test file for macro BOOST_NO_UNREACHABLE_RETURN_DETECTION +// This file should compile, if it does not then +// BOOST_NO_UNREACHABLE_RETURN_DETECTION needs to be defined. +// see boost_no_ret_det.cxx for more details + +// Do not edit this file, it was generated automatically by +// ../tools/generate from boost_no_ret_det.cxx on +// Mon Dec 9 12:06:12 2002 + +// Must not have BOOST_ASSERT_CONFIG set; it defeats +// the objective of this file: +#ifdef BOOST_ASSERT_CONFIG +# undef BOOST_ASSERT_CONFIG +#endif + +#include +#include "test.hpp" + +#ifndef BOOST_NO_UNREACHABLE_RETURN_DETECTION +#include "boost_no_ret_det.cxx" +#else +namespace boost_no_unreachable_return_detection = empty_boost; +#endif + +int cpp_main( int, char *[] ) +{ + return boost_no_unreachable_return_detection::test(); +} +