Boost C++ Libraries: Ticket #4666: boost::variant gives several warnings (fix suggestions included) https://svn.boost.org/trac10/ticket/4666 <p> I am using several compiler options with gcc to increase the warning level. Especially 3 of them are raising warnings : </p> <p> 1) -Wshadow Too warn when a variable is shadowing/hiding another variable/method This occurs in boostvariant/variant.hpp </p> <pre class="wiki">void indicate_which(int which) { which_ = static_cast&lt;which_t&gt;( which ); } void indicate_backup_which(int which) { which_ = static_cast&lt;which_t&gt;( -(which + 1) ); } </pre><p> the local which is shadowing the member method which. </p> <p> My suggestion to fix would be : </p> <pre class="wiki"> void indicate_which(int which_in) { which_ = static_cast&lt;which_t&gt;( which_in ); } void indicate_backup_which(int which_in) { which_ = static_cast&lt;which_t&gt;( -(which_in + 1) ); } </pre><p> So I just renamed to local to which_in </p> <p> 2) -Wswitch-default warn when a switch statement doesn't have a default case. This occurs at : boost/variant/detail/visitation_impl.hpp </p> <pre class="wiki"> // ...switch on the target which-index value... switch (logical_which) { // ...applying the appropriate case: # define BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE(z, N, _) \ case (Which::value + (N)): \ return visitation_impl_invoke( \ internal_which, visitor, storage \ , static_cast&lt;BOOST_PP_CAT(T,N)*&gt;(0) \ , no_backup_flag, 1L \ ); \ /**/ BOOST_PP_REPEAT( BOOST_VARIANT_VISITATION_UNROLLING_LIMIT , BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE , _ ) # undef BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE } </pre><p> My suggestion is to add the following just in front of the end brace of the switch : </p> <pre class="wiki"> default: break; </pre><p> 3) -Wundef warns if an undefined identifier is evaluated in an #if directive This occurs at : boost/mpl/has_xxx.hpp It occurs 4 times (that I ran into, within all the ifdef stuff it might occur a few times more). </p> <pre class="wiki"># if !BOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION # define BOOST_MPL_HAS_MEMBER_REJECT(args, member_macro) \ template&lt; typename V &gt; \ static boost::mpl::aux::no_tag \ BOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)(...); \ /**/ # else # define BOOST_MPL_HAS_MEMBER_REJECT(args, member_macro) \ static boost::mpl::aux::no_tag \ BOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)(...); \ /**/ # endif </pre><p> The question is : BOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION, does it need to have a special value (for example : not 0), or is it just a matter of beind defined or not. In the latter case, this are my suggestions on how to fix : </p> <p> line 344 --&gt; # if not defined (BOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION) line 357 --&gt; # if not defined (BOOST_MPL_HAS_XXX_NO_WRAPPED_TYPES) line 386 --&gt; # if not defined (BOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION) line 458 --&gt; # if defined (BOOST_MPL_HAS_XXX_NEEDS_TEMPLATE_SFINAE) </p> <p> What do you think ? </p> <p> kind regards, Lieven </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4666 Trac 1.4.3 Steven Watanabe Thu, 07 Apr 2011 15:38:34 GMT owner, component changed https://svn.boost.org/trac10/ticket/4666#comment:1 https://svn.boost.org/trac10/ticket/4666#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">ebf</span> to <span class="trac-author">Aleksey Gurtovoy</span> </li> <li><strong>component</strong> <span class="trac-field-old">variant</span> → <span class="trac-field-new">mpl</span> </li> </ul> <p> I addressed the warnings from variant in <a class="changeset" href="https://svn.boost.org/trac10/changeset/71083" title="Supress warnings from variant. Refs #4666.">[71083]</a>. Reassigning to MPL for the last one. </p> Ticket