Apply patch from #8408.

Fixes #8408.

[SVN r83958]
This commit is contained in:
John Maddock
2013-04-18 17:50:17 +00:00
parent 1f5100001f
commit bffa0772d8
8 changed files with 126 additions and 22 deletions

View File

@ -3382,6 +3382,54 @@
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">BOOST_FALLTHROUGH</span></code>
</p>
</td>
<td>
<p>
The BOOST_FALLTHROUGH macro can be used to annotate implicit fall-through
between switch labels:
</p>
<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>
<span class="keyword">case</span> <span class="number">40</span><span class="special">:</span>
<span class="keyword">case</span> <span class="number">41</span><span class="special">:</span>
<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>
<span class="special">++</span><span class="identifier">x</span><span class="special">;</span>
<span class="identifier">BOOST_FALLTHROUGH</span><span class="special">;</span> <span class="comment">// Use instead of/along with annotations in </span>
<span class="comment">// comments. </span>
<span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">case</span> <span class="number">42</span><span class="special">:</span>
<span class="special">...</span>
</pre>
<p>
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.
</p>
<p>
When compiled with Clang &gt;3.2 in C++11 mode, the BOOST_FALLTHROUGH
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>
attribute, which is analysed when performing switch labels fall-through
diagnostic ('-Wimplicit-fallthrough'). See clang <a href="http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough" target="_top">documentation
on language extensions for details.</a>
</p>
<p>
When used with unsupported compilers, the BOOST_FALLTHROUGH macro
has no effect on diagnostics.
</p>
<p>
In either case this macro has no effect on runtime behavior and
performance of code.
</p>
</td>
</tr>
<tr>
<td>
<p>
<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>

View File

@ -951,7 +951,7 @@
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: February 19, 2013 at 16:25:18 GMT</small></p></td>
<td align="left"><p><small>Last revised: April 18, 2013 at 17:44:14 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>

View File

@ -862,6 +862,41 @@ struct foo{
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 [@http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough
documentation on language extensions for details.]
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)`

View File

@ -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

View File

@ -883,6 +883,16 @@ namespace std{ using ::type_info; }
# define BOOST_NOEXCEPT_IF(Predicate) noexcept((Predicate))
# define BOOST_NOEXCEPT_EXPR(Expression) noexcept((Expression))
#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

View File

@ -65,4 +65,5 @@ test-suite config
]
[ compile-fail threads/test_thread_fail1.cpp ]
[ compile-fail threads/test_thread_fail2.cpp ]
[ compile boost_fallthrough_test.cpp : <toolset>clang:<cxxflags>"-std=c++11 -Wimplicit-fallthrough" <warnings-as-errors>on <warnings>all ]
;

View File

@ -0,0 +1,20 @@
// 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(int n)
{
switch (n)
{
case 0:
n++;
BOOST_FALLTHROUGH;
case 1:
n++;
break;
}
return n;
}

View File

@ -1100,27 +1100,6 @@ void print_boost_macros()
PRINT_MACRO(BOOST_NO_USING_TEMPLATE);
PRINT_MACRO(BOOST_NO_VOID_RETURNS);
// END GENERATED BLOCK
PRINT_MACRO(BOOST_INTEL);
@ -1132,6 +1111,7 @@ void print_boost_macros()
PRINT_MACRO(BOOST_STATIC_CONSTEXPR);
PRINT_MACRO(BOOST_NOEXCEPT);
PRINT_MACRO(BOOST_FORCEINLINE);
PRINT_MACRO(BOOST_FALLTHROUGH);
}
void print_separator()