Opened 7 years ago

Last modified 4 years ago

#11640 new Bugs

scope_exit: -Wshadow warning issued

Reported by: lukasz.czajczyk@… Owned by: Lorenzo Caminiti
Milestone: To Be Determined Component: scope_exit
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:

Description

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.

Sample program:

Code highlighting:

#include <boost/scope_exit.hpp>

int main()
{
   int i, j = 0;
   BOOST_SCOPE_EXIT(i, j)
   {} BOOST_SCOPE_EXIT_END
   return 0;
}

Compiled with clang++ -isystem /tmp/boost/boost_1_58_0 -Wshadow

warning: declaration shadows a local variable [-Wshadow]

BOOST_SCOPE_EXIT(i, j)

/tmp/boost/boost_1_58_0/boost/scope_exit.hpp:900:17: note: expanded from macro 'BOOST_SCOPE_EXIT'

VA_ARGS)

/tmp/boost/boost_1_58_0/boost/scope_exit.hpp:893:59: note: expanded from macro 'BOOST_SCOPE_EXIT_ID'

BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(VA_ARGS)))

/tmp/boost/boost_1_58_0/boost/scope_exit.hpp:178:59: note: expanded from macro 'BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST'

BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK, VA_ARGS)

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

/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

/tmp/boost/boost_1_58_0/boost/scope_exit.hpp:316:5: note: expanded from macro 'BOOST_SCOPE_EXIT_AUX_ARG_DECL'

var

p.cxx:5:8: note: previous declaration is here

int i, j = 0;

Change History (3)

comment:1 by anonymous, 6 years ago

We have the same problem, are there any news for this topic?

comment:2 by lukasz.czajczyk@…, 6 years ago

The same issue happens with Boost 1.62 and Clang 4.0.

The output from clang is simpler:

i.cxx:6:22: warning: declaration shadows a local variable [-Wshadow]
   BOOST_SCOPE_EXIT(&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(&i, j)
                        ^
i.cxx:5:11: note: previous declaration is here
   int i, j = 0;
          ^
2 warnings generated.

comment:3 by anonymous, 4 years ago

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.

Note: See TracTickets for help on using tickets.