
Dustin Spicuzza wrote:
David Abrahams wrote:
on Sat Feb 07 2009, Sebastian Redl <sebastian.redl-AT-getdesigned.at> wrote:
John Bytheway wrote:
I'd suggest a simpler (from the user perspective) solution would be to have BOOST_FOREACH paste __LINE__ into its variable names. Then the problem would only occur if nested BOOST_FOREACHs were used on the same line. Asking users not to do that seems a lot more reasonable than asking them not to use -Wshadow or not to use nested BOOST_FOREACHs at all.
I'm pretty sure you'd need a special variant for MS compilers, since their __LINE__ expansion is not cleanly pasteable. (You can use their counting macro instead.)
Doesn't using BOOST_PP_CAT work?
Ok, so attached is a simple patch to BOOST_FOREACH (v1.37) using the __LINE__ mechanism suggested. It works for gcc 4.3, but I don't have access to other compilers at the moment -- and even if I did, I'm not quite sure of the best way to mix the __LINE__ and __COUNTER__ implementations correctly.
Thanks for the patch. I've made my own minor modifications and committed it to trunk. Since I also recall there being problems on msvc with __LINE__ and msvc's edit-and-continue feature, I'm simply not mangling names for msvc. That's ok because msvc doesn't emit shadow warnings, AFAIK. (Using __COUNTER__ on msvc would actually be wrong because it would become impossible to refer back to an identifier created previously.) -- Eric Niebler BoostPro Computing http://www.boostpro.com