Boost C++ Libraries: Ticket #11640: scope_exit: -Wshadow warning issued https://svn.boost.org/trac10/ticket/11640 <p> Hi, BOOST_SCOPE_EXIT emits warning: declaration shadows a local variable [-Wshadow] in CLANG compiler. Tested with boost 1.54-1.58 and CLANG 3.5-3.7. The issue does not occur on GCC when boost is included using -isystem. </p> <p> Sample program: </p> <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/scope_exit.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">BOOST_SCOPE_EXIT</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">)</span> <span class="p">{}</span> <span class="n">BOOST_SCOPE_EXIT_END</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></div><p> Compiled with clang++ -isystem /tmp/boost/boost_1_58_0 -Wshadow </p> <blockquote> <p> warning: declaration shadows a local variable [-Wshadow] </p> <blockquote> <p> BOOST_SCOPE_EXIT(i, j) </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> </blockquote> <p> /tmp/boost/boost_1_58_0/boost/scope_exit.hpp:900:17: note: expanded from macro 'BOOST_SCOPE_EXIT' </p> <blockquote> <p> <span class="underline">VA_ARGS</span>) <sup> </sup></p> </blockquote> <p> /tmp/boost/boost_1_58_0/boost/scope_exit.hpp:893:59: note: expanded from macro 'BOOST_SCOPE_EXIT_ID' </p> <blockquote> <p> BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(<span class="underline">VA_ARGS</span>))) </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> <p> /tmp/boost/boost_1_58_0/boost/scope_exit.hpp:178:59: note: expanded from macro 'BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST' </p> <blockquote> <p> BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK, <span class="underline">VA_ARGS</span>) </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> <p> note: (skipping 66 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) /tmp/boost/boost_1_58_0/boost/preprocessor/list/adt.hpp:35:63: note: expanded from macro 'BOOST_PP_LIST_FIRST_D' # define BOOST_PP_LIST_FIRST_D(list) BOOST_PP_LIST_FIRST_I list </p> <blockquote> <p> <sup> </sup></p> </blockquote> <p> /tmp/boost/boost_1_58_0/boost/preprocessor/list/adt.hpp:40:44: note: expanded from macro 'BOOST_PP_LIST_FIRST_I' # define BOOST_PP_LIST_FIRST_I(head, tail) head </p> <blockquote> <p> <sup> </sup></p> </blockquote> <p> /tmp/boost/boost_1_58_0/boost/scope_exit.hpp:316:5: note: expanded from macro 'BOOST_SCOPE_EXIT_AUX_ARG_DECL' </p> <blockquote> <p> var <sup> </sup></p> </blockquote> <p> p.cxx:5:8: note: previous declaration is here </p> <blockquote> <p> int i, j = 0; </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11640 Trac 1.4.3 anonymous Thu, 23 Mar 2017 13:33:00 GMT <link>https://svn.boost.org/trac10/ticket/11640#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11640#comment:1</guid> <description> <p> We have the same problem, are there any news for this topic? </p> </description> <category>Ticket</category> </item> <item> <author>lukasz.czajczyk@…</author> <pubDate>Fri, 24 Mar 2017 12:57:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11640#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11640#comment:2</guid> <description> <p> The same issue happens with Boost 1.62 and Clang 4.0. </p> <p> The output from clang is simpler: </p> <pre class="wiki">i.cxx:6:22: warning: declaration shadows a local variable [-Wshadow] BOOST_SCOPE_EXIT(&amp;i, j) ^ i.cxx:5:8: note: previous declaration is here int i, j = 0; ^ i.cxx:6:25: warning: declaration shadows a local variable [-Wshadow] BOOST_SCOPE_EXIT(&amp;i, j) ^ i.cxx:5:11: note: previous declaration is here int i, j = 0; ^ 2 warnings generated. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 19 Jun 2018 11:38:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11640#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11640#comment:3</guid> <description> <p> This is in the nature of the function if no closures are supported. The macro will re-declare the variables with the same name to bring them into the scope of the scoped function. This will lead in to a shadowing of the original variables. </p> </description> <category>Ticket</category> </item> </channel> </rss>