Ticket #8408: boost-config-fallthrough.patch

File boost-config-fallthrough.patch, 18.9 KB (added by Alexander Kornienko <alexfh@…>, 10 years ago)

Patch for Boost.Config: adds BOOST_FALLTHROUGH macro + tests + documentation.

  • boost/config/compiler/clang.hpp

     
    3838#  define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))
    3939#endif
    4040
     41//
     42// The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through
     43// between switch labels.
     44//
     45#if __cplusplus >= 201103L && defined(__has_warning)
     46#  if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
     47#    define BOOST_FALLTHROUGH [[clang::fallthrough]]
     48#  endif
     49#endif
     50
    4151#if !__has_feature(cxx_auto_type)
    4252#  define BOOST_NO_CXX11_AUTO_DECLARATIONS
    4353#  define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS
  • boost/config/suffix.hpp

     
    885885#endif
    886886
    887887//
     888// Helper macro BOOST_FALLTHROUGH
     889// Fallback definition of BOOST_FALLTHROUGH macro used to mark intended
     890// fall-through between case labels in a switch statement. We use a definition
     891// that requires a semicolon after it to avoid at least one type of misuse even
     892// on unsupported compilers.
     893//
     894#ifndef BOOST_FALLTHROUGH
     895#  define BOOST_FALLTHROUGH ((void)0)
     896#endif
     897
     898//
    888899// constexpr workarounds
    889900//
    890901#if defined(BOOST_NO_CXX11_CONSTEXPR)
  • libs/config/doc/html/boost_config/acknowledgements.html

     
    33<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    44<title>Acknowledgements</title>
    55<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
    6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
     6<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
    77<link rel="home" href="../index.html" title="Boost.Config">
    88<link rel="up" href="../index.html" title="Boost.Config">
    99<link rel="prev" href="rationale.html" title="Rationale">
  • libs/config/doc/html/boost_config/boost_macro_reference.html

     
    33<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    44<title>Boost Macro Reference</title>
    55<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
    6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
     6<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
    77<link rel="home" href="../index.html" title="Boost.Config">
    88<link rel="up" href="../index.html" title="Boost.Config">
    99<link rel="prev" href="../index.html" title="Boost.Config">
     
    2626<div class="titlepage"><div><div><h2 class="title" style="clear: both">
    2727<a name="boost_config.boost_macro_reference"></a><a class="link" href="boost_macro_reference.html" title="Boost Macro Reference">Boost Macro Reference</a>
    2828</h2></div></div></div>
    29 <div class="toc"><dl>
     29<div class="toc"><dl class="toc">
    3030<dt><span class="section"><a href="boost_macro_reference.html#boost_config.boost_macro_reference.macros_that_describe_c__03_defects">Macros
    3131      that describe C++03 defects</a></span></dt>
    3232<dt><span class="section"><a href="boost_macro_reference.html#boost_config.boost_macro_reference.macros_that_describe_optional_features">Macros
     
    33843384<tr>
    33853385<td>
    33863386                <p>
     3387                  <code class="computeroutput"><span class="identifier">BOOST_FALLTHROUGH</span></code>
     3388                </p>
     3389              </td>
     3390<td>
     3391                <p>
     3392                  The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through
     3393                  between switch labels:
     3394</p>
     3395<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">switch</span> <span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">{</span>
     3396  <span class="keyword">case</span> <span class="number">40</span><span class="special">:</span>
     3397  <span class="keyword">case</span> <span class="number">41</span><span class="special">:</span>
     3398    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">truth_is_out_there</span><span class="special">)</span> <span class="special">{</span>
     3399      <span class="special">++</span><span class="identifier">x</span><span class="special">;</span>
     3400      <span class="identifier">BOOST_FALLTHROUGH</span><span class="special">;</span>  <span class="comment">// Use instead of/along with annotations in</span>
     3401                          <span class="comment">// comments.</span>
     3402    <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
     3403      <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span>
     3404    <span class="special">}</span>
     3405  <span class="keyword">case</span> <span class="number">42</span><span class="special">:</span>
     3406    <span class="special">...</span>
     3407</pre>
     3408<p>
     3409                  As shown in the example above, the BOOST_FALLTHROUGH macro should
     3410                  be followed by a semicolon. It is designed to mimic control-flow
     3411                  statements like 'break;', so it can be placed in most places where
     3412                  'break;' can, but only if there are no statements on the execution
     3413                  path between it and the next switch label.
     3414                </p>
     3415                <p>
     3416                  When compiled with Clang &gt;3.2 in C++11 mode, the BOOST_FALLTHROUGH
     3417                  macro is expanded to <code class="computeroutput"><span class="special">[[</span><span class="identifier">clang</span><span class="special">::</span><span class="identifier">fallthrough</span><span class="special">]]</span></code>
     3418                  attribute, which is analysed when performing switch labels fall-through
     3419                  diagnostic ('-Wimplicit-fallthrough'). See clang documentation
     3420                  on language extensions for details: http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough
     3421                </p>
     3422                <p>
     3423                  When used with unsupported compilers, the BOOST_FALLTHROUGH macro
     3424                  has no effect on diagnostics.
     3425                </p>
     3426                <p>
     3427                  In either case this macro has no effect on runtime behavior and
     3428                  performance of code.
     3429                </p>
     3430              </td>
     3431</tr>
     3432<tr>
     3433<td>
     3434                <p>
    33873435                  <code class="computeroutput"><span class="identifier">BOOST_EXPLICIT_TEMPLATE_TYPE</span><span class="special">(</span><span class="identifier">t</span><span class="special">)</span></code> <code class="computeroutput"><span class="identifier">BOOST_EXPLICIT_TEMPLATE_NON_TYPE</span><span class="special">(</span><span class="identifier">t</span><span class="special">,</span><span class="identifier">v</span><span class="special">)</span></code> <code class="computeroutput"><span class="identifier">BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE</span><span class="special">(</span><span class="identifier">t</span><span class="special">)</span></code> <code class="computeroutput"><span class="identifier">BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE</span><span class="special">(</span><span class="identifier">t</span><span class="special">,</span><span class="identifier">v</span><span class="special">)</span></code>
    33883436                </p>
    33893437              </td>
     
    49234971<a name="boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code"></a><a class="link" href="boost_macro_reference.html#boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code" title="Macros for libraries with separate source code">Macros
    49244972      for libraries with separate source code</a>
    49254973</h3></div></div></div>
    4926 <div class="toc"><dl>
     4974<div class="toc"><dl class="toc">
    49274975<dt><span class="section"><a href="boost_macro_reference.html#boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code.macros_controlling_shared_library_symbol_visibility">Macros
    49284976        controlling shared library symbol visibility</a></span></dt>
    49294977<dt><span class="section"><a href="boost_macro_reference.html#boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code.abi_fixing">ABI
  • libs/config/doc/html/boost_config/guidelines_for_boost_authors.html

     
    33<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    44<title>Guidelines for Boost Authors</title>
    55<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
    6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
     6<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
    77<link rel="home" href="../index.html" title="Boost.Config">
    88<link rel="up" href="../index.html" title="Boost.Config">
    99<link rel="prev" href="boost_macro_reference.html" title="Boost Macro Reference">
     
    2727<a name="boost_config.guidelines_for_boost_authors"></a><a class="link" href="guidelines_for_boost_authors.html" title="Guidelines for Boost Authors">Guidelines for
    2828    Boost Authors</a>
    2929</h2></div></div></div>
    30 <div class="toc"><dl>
     30<div class="toc"><dl class="toc">
    3131<dt><span class="section"><a href="guidelines_for_boost_authors.html#boost_config.guidelines_for_boost_authors.warnings">Disabling
    3232      Compiler Warnings</a></span></dt>
    3333<dt><span class="section"><a href="guidelines_for_boost_authors.html#boost_config.guidelines_for_boost_authors.adding_new_defect_macros">Adding
  • libs/config/doc/html/boost_config/rationale.html

     
    33<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    44<title>Rationale</title>
    55<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
    6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
     6<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
    77<link rel="home" href="../index.html" title="Boost.Config">
    88<link rel="up" href="../index.html" title="Boost.Config">
    99<link rel="prev" href="guidelines_for_boost_authors.html" title="Guidelines for Boost Authors">
     
    2626<div class="titlepage"><div><div><h2 class="title" style="clear: both">
    2727<a name="boost_config.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a>
    2828</h2></div></div></div>
    29 <div class="toc"><dl>
     29<div class="toc"><dl class="toc">
    3030<dt><span class="section"><a href="rationale.html#boost_config.rationale.the_problem">The problem</a></span></dt>
    3131<dt><span class="section"><a href="rationale.html#boost_config.rationale.the_solution">The solution</a></span></dt>
    3232</dl></div>
  • libs/config/doc/html/index.html

     
    33<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    44<title>Boost.Config</title>
    55<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
    6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
     6<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
    77<link rel="home" href="index.html" title="Boost.Config">
    88<link rel="next" href="boost_config/boost_macro_reference.html" title="Boost Macro Reference">
    99</head>
     
    3939</div>
    4040<div class="toc">
    4141<p><b>Table of Contents</b></p>
    42 <dl>
     42<dl class="toc">
    4343<dt><span class="section"><a href="index.html#boost_config.configuring_boost_for_your_platform">Configuring
    4444    Boost for Your Platform</a></span></dt>
    4545<dd><dl>
     
    102102<a name="boost_config.configuring_boost_for_your_platform"></a><a class="link" href="index.html#boost_config.configuring_boost_for_your_platform" title="Configuring Boost for Your Platform">Configuring
    103103    Boost for Your Platform</a>
    104104</h2></div></div></div>
    105 <div class="toc"><dl>
     105<div class="toc"><dl class="toc">
    106106<dt><span class="section"><a href="index.html#boost_config.configuring_boost_for_your_platform.using_the_default_boost_configuration">Using
    107107      the default boost configuration</a></span></dt>
    108108<dt><span class="section"><a href="index.html#boost_config.configuring_boost_for_your_platform.the__boost_config_hpp__header">The
     
    684684<a name="boost_config.configuring_boost_for_your_platform.advanced_configuration_usage"></a><a class="link" href="index.html#boost_config.configuring_boost_for_your_platform.advanced_configuration_usage" title="Advanced configuration usage">Advanced
    685685      configuration usage</a>
    686686</h3></div></div></div>
    687 <div class="toc"><dl>
     687<div class="toc"><dl class="toc">
    688688<dt><span class="section"><a href="index.html#boost_config.configuring_boost_for_your_platform.advanced_configuration_usage.example_1__creating_our_own_frozen_configuration">Example
    689689        1: creating our own frozen configuration</a></span></dt>
    690690<dt><span class="section"><a href="index.html#boost_config.configuring_boost_for_your_platform.advanced_configuration_usage.example_2__skipping_files_that_you_don_t_need">Example
     
    951951</div>
    952952</div>
    953953<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
    954 <td align="left"><p><small>Last revised: February 19, 2013 at 16:25:18 GMT</small></p></td>
     954<td align="left"><p><small>Last revised: April 05, 2013 at 23:29:41 GMT</small></p></td>
    955955<td align="right"><div class="copyright-footer"></div></td>
    956956</tr></table>
    957957<hr>
  • libs/config/doc/macro_reference.qbk

     
    862862Normally evaluates to nothing, but evaluates to return x; if the compiler
    863863requires a return, even when it can never be reached.
    864864]]
     865[[`BOOST_FALLTHROUGH`][
     866The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through
     867between switch labels:
     868``
     869 switch (x) {
     870   case 40:
     871   case 41:
     872     if (truth_is_out_there) {
     873       ++x;
     874       BOOST_FALLTHROUGH;  // Use instead of/along with annotations in
     875                           // comments.
     876     } else {
     877       return x;
     878     }
     879   case 42:
     880     ...
     881``
     882As shown in the example above, the BOOST_FALLTHROUGH macro should be
     883followed by a semicolon. It is designed to mimic control-flow statements
     884like 'break;', so it can be placed in most places where 'break;' can, but
     885only if there are no statements on the execution path between it and the
     886next switch label.
     887
     888When compiled with Clang >3.2 in C++11 mode, the BOOST_FALLTHROUGH macro is
     889expanded to `[[clang::fallthrough]]` attribute, which is analysed when
     890performing switch labels fall-through diagnostic ('-Wimplicit-fallthrough').
     891See clang documentation on language extensions for details:
     892http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough
     893
     894When used with unsupported compilers, the BOOST_FALLTHROUGH macro has no
     895effect on diagnostics.
     896
     897In either case this macro has no effect on runtime behavior and performance
     898of code.
     899]]
    865900[[`BOOST_EXPLICIT_TEMPLATE_TYPE(t)`
    866901  `BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t,v)`
    867902  `BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t)`
  • libs/config/test/Jamfile.v2

     
    6565    ]
    6666    [ compile-fail threads/test_thread_fail1.cpp ]
    6767    [ compile-fail threads/test_thread_fail2.cpp ]
     68    [ compile-fail boost_fallthrough_fail.cpp ]
     69    [ compile boost_fallthrough_test.cpp : <toolset>clang:<cxxflags>"-std=c++11 -Werror -Wimplicit-fallthrough" ]
    6870  ;
  • libs/config/test/boost_fallthrough_fail.cpp

     
     1//  Use, modification and distribution are subject to the
     2//  Boost Software License, Version 1.0. (See accompanying file
     3//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     4
     5#include <boost/config.hpp>
     6
     7int test(int n)
     8{
     9   switch (n)
     10   {
     11      case 0:
     12         n++;
     13         BOOST_FALLTHROUGH
     14      case 1:
     15         n++;
     16         break;
     17   }
     18   return n;
     19}
  • libs/config/test/boost_fallthrough_test.cpp

     
     1//  Use, modification and distribution are subject to the
     2//  Boost Software License, Version 1.0. (See accompanying file
     3//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     4
     5#include <boost/config.hpp>
     6
     7int test(int n)
     8{
     9   switch (n)
     10   {
     11      case 0:
     12         n++;
     13         BOOST_FALLTHROUGH;
     14      case 1:
     15         n++;
     16         break;
     17   }
     18   return n;
     19}
  • libs/config/test/boost_no_std_wstreambuf.ipp

     
    6161   case ::std::ios_base::beg:
    6262      if((off < 0) || (off > size))
    6363         return pos_type(off_type(-1));
    64       else
    65          this->setg(g, g + off, g + size);
     64      this->setg(g, g + off, g + size);
     65      BOOST_FALLTHROUGH;
    6666   case ::std::ios_base::end:
    6767      if((off < 0) || (off > size))
    6868         return pos_type(off_type(-1));
    69       else
    70          this->setg(g, g + size - off, g + size);
     69      this->setg(g, g + size - off, g + size);
     70      BOOST_FALLTHROUGH;
    7171   case ::std::ios_base::cur:
    7272   {
    7373      int newpos = pos + off;
  • libs/config/test/config_info.cpp

     
    11251125   PRINT_MACRO(BOOST_MSVC);
    11261126   PRINT_MACRO(BOOST_STD_EXTENSION_NAMESPACE);
    11271127   PRINT_MACRO(BOOST_UNREACHABLE_RETURN(0));
     1128   PRINT_MACRO(BOOST_FALLTHROUGH);
    11281129   PRINT_MACRO(BOOST_CONSTEXPR);
    11291130   PRINT_MACRO(BOOST_CONSTEXPR_OR_CONST);
    11301131   PRINT_MACRO(BOOST_STATIC_CONSTEXPR);