Index: boost/config/compiler/clang.hpp =================================================================== --- boost/config/compiler/clang.hpp (revision 83820) +++ boost/config/compiler/clang.hpp (working copy) @@ -38,6 +38,16 @@ # define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default"))) #endif +// +// The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through +// between switch labels. +// +#if __cplusplus >= 201103L && defined(__has_warning) +# if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough") +# define BOOST_FALLTHROUGH [[clang::fallthrough]] +# endif +#endif + #if !__has_feature(cxx_auto_type) # define BOOST_NO_CXX11_AUTO_DECLARATIONS # define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS Index: boost/config/suffix.hpp =================================================================== --- boost/config/suffix.hpp (revision 83820) +++ boost/config/suffix.hpp (working copy) @@ -885,6 +885,17 @@ #endif // +// Helper macro BOOST_FALLTHROUGH +// Fallback definition of BOOST_FALLTHROUGH macro used to mark intended +// fall-through between case labels in a switch statement. We use a definition +// that requires a semicolon after it to avoid at least one type of misuse even +// on unsupported compilers. +// +#ifndef BOOST_FALLTHROUGH +# define BOOST_FALLTHROUGH ((void)0) +#endif + +// // constexpr workarounds // #if defined(BOOST_NO_CXX11_CONSTEXPR) Index: libs/config/doc/html/boost_config/acknowledgements.html =================================================================== --- libs/config/doc/html/boost_config/acknowledgements.html (revision 83820) +++ libs/config/doc/html/boost_config/acknowledgements.html (working copy) @@ -3,7 +3,7 @@ Acknowledgements - + Index: libs/config/doc/html/boost_config/boost_macro_reference.html =================================================================== --- libs/config/doc/html/boost_config/boost_macro_reference.html (revision 83820) +++ libs/config/doc/html/boost_config/boost_macro_reference.html (working copy) @@ -3,7 +3,7 @@ Boost Macro Reference - + @@ -26,7 +26,7 @@

Boost Macro Reference

-
+
Macros that describe C++03 defects
Macros @@ -3384,6 +3384,54 @@

+ BOOST_FALLTHROUGH +

+ + +

+ The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through + between switch labels: +

+
switch (x) {
+  case 40:
+  case 41:
+    if (truth_is_out_there) {
+      ++x;
+      BOOST_FALLTHROUGH;  // Use instead of/along with annotations in
+                          // comments.
+    } else {
+      return x;
+    }
+  case 42:
+    ...
+
+

+ As shown in the example above, the BOOST_FALLTHROUGH macro should + be followed by a semicolon. It is designed to mimic control-flow + statements like 'break;', so it can be placed in most places where + 'break;' can, but only if there are no statements on the execution + path between it and the next switch label. +

+

+ When compiled with Clang >3.2 in C++11 mode, the BOOST_FALLTHROUGH + macro is expanded to [[clang::fallthrough]] + attribute, which is analysed when performing switch labels fall-through + diagnostic ('-Wimplicit-fallthrough'). See clang documentation + on language extensions for details: http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough +

+

+ When used with unsupported compilers, the BOOST_FALLTHROUGH macro + has no effect on diagnostics. +

+

+ In either case this macro has no effect on runtime behavior and + performance of code. +

+ + + + +

BOOST_EXPLICIT_TEMPLATE_TYPE(t) BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t,v) BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t) BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t,v)

@@ -4923,7 +4971,7 @@
Macros for libraries with separate source code
-
+
-
+
Disabling Compiler Warnings
Adding Index: libs/config/doc/html/boost_config/rationale.html =================================================================== --- libs/config/doc/html/boost_config/rationale.html (revision 83820) +++ libs/config/doc/html/boost_config/rationale.html (working copy) @@ -3,7 +3,7 @@ Rationale - + @@ -26,7 +26,7 @@ -
+ Index: libs/config/doc/html/index.html =================================================================== --- libs/config/doc/html/index.html (revision 83820) +++ libs/config/doc/html/index.html (working copy) @@ -3,7 +3,7 @@ Boost.Config - + @@ -39,7 +39,7 @@
-
+
-
+
- +

Last revised: February 19, 2013 at 16:25:18 GMT

Last revised: April 05, 2013 at 23:29:41 GMT


Index: libs/config/doc/macro_reference.qbk =================================================================== --- libs/config/doc/macro_reference.qbk (revision 83820) +++ libs/config/doc/macro_reference.qbk (working copy) @@ -862,6 +862,41 @@ Normally evaluates to nothing, but evaluates to return x; if the compiler requires a return, even when it can never be reached. ]] +[[`BOOST_FALLTHROUGH`][ +The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through +between switch labels: +`` + switch (x) { + case 40: + case 41: + if (truth_is_out_there) { + ++x; + BOOST_FALLTHROUGH; // Use instead of/along with annotations in + // comments. + } else { + return x; + } + case 42: + ... +`` +As shown in the example above, the BOOST_FALLTHROUGH macro should be +followed by a semicolon. It is designed to mimic control-flow statements +like 'break;', so it can be placed in most places where 'break;' can, but +only if there are no statements on the execution path between it and the +next switch label. + +When compiled with Clang >3.2 in C++11 mode, the BOOST_FALLTHROUGH macro is +expanded to `[[clang::fallthrough]]` attribute, which is analysed when +performing switch labels fall-through diagnostic ('-Wimplicit-fallthrough'). +See clang documentation on language extensions for details: +http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough + +When used with unsupported compilers, the BOOST_FALLTHROUGH macro has no +effect on diagnostics. + +In either case this macro has no effect on runtime behavior and performance +of code. +]] [[`BOOST_EXPLICIT_TEMPLATE_TYPE(t)` `BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t,v)` `BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t)` Index: libs/config/test/Jamfile.v2 =================================================================== --- libs/config/test/Jamfile.v2 (revision 83820) +++ libs/config/test/Jamfile.v2 (working copy) @@ -65,4 +65,6 @@ ] [ compile-fail threads/test_thread_fail1.cpp ] [ compile-fail threads/test_thread_fail2.cpp ] + [ compile-fail boost_fallthrough_fail.cpp ] + [ compile boost_fallthrough_test.cpp : clang:"-std=c++11 -Werror -Wimplicit-fallthrough" ] ; Index: libs/config/test/boost_fallthrough_fail.cpp =================================================================== --- libs/config/test/boost_fallthrough_fail.cpp (revision 0) +++ libs/config/test/boost_fallthrough_fail.cpp (working copy) @@ -0,0 +1,19 @@ +// 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 + +int test(int n) +{ + switch (n) + { + case 0: + n++; + BOOST_FALLTHROUGH + case 1: + n++; + break; + } + return n; +} Index: libs/config/test/boost_fallthrough_test.cpp =================================================================== --- libs/config/test/boost_fallthrough_test.cpp (revision 0) +++ libs/config/test/boost_fallthrough_test.cpp (working copy) @@ -0,0 +1,19 @@ +// 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 + +int test(int n) +{ + switch (n) + { + case 0: + n++; + BOOST_FALLTHROUGH; + case 1: + n++; + break; + } + return n; +} Index: libs/config/test/boost_no_std_wstreambuf.ipp =================================================================== --- libs/config/test/boost_no_std_wstreambuf.ipp (revision 83820) +++ libs/config/test/boost_no_std_wstreambuf.ipp (working copy) @@ -61,13 +61,13 @@ case ::std::ios_base::beg: if((off < 0) || (off > size)) return pos_type(off_type(-1)); - else - this->setg(g, g + off, g + size); + this->setg(g, g + off, g + size); + BOOST_FALLTHROUGH; case ::std::ios_base::end: if((off < 0) || (off > size)) return pos_type(off_type(-1)); - else - this->setg(g, g + size - off, g + size); + this->setg(g, g + size - off, g + size); + BOOST_FALLTHROUGH; case ::std::ios_base::cur: { int newpos = pos + off; Index: libs/config/test/config_info.cpp =================================================================== --- libs/config/test/config_info.cpp (revision 83820) +++ libs/config/test/config_info.cpp (working copy) @@ -1125,6 +1125,7 @@ PRINT_MACRO(BOOST_MSVC); PRINT_MACRO(BOOST_STD_EXTENSION_NAMESPACE); PRINT_MACRO(BOOST_UNREACHABLE_RETURN(0)); + PRINT_MACRO(BOOST_FALLTHROUGH); PRINT_MACRO(BOOST_CONSTEXPR); PRINT_MACRO(BOOST_CONSTEXPR_OR_CONST); PRINT_MACRO(BOOST_STATIC_CONSTEXPR);