Commit 1dee6ec9 authored by Jim Meyering's avatar Jim Meyering Committed by Facebook Github Bot

folly/Foreach.h: fix FOR_EACH_R and FOR_EACH_KV to avoid shadowing warnings

Summary:
Fix these macros not to self-shadow for nested uses.
How? Make each local variable name include __LINE__.
This works in most cases, but not all: if you put the
nested uses all on one line, you'll still get shadowing warnings.

Reviewed By: yfeldblum

Differential Revision: D4161553

fbshipit-source-id: 9e11ae6778272c733a4c820cfb30c5db59998a5b
parent 7213df65
......@@ -72,11 +72,11 @@
* using rbegin() and rend().
*/
#define FOR_EACH_R(i, c) \
if (bool FOR_EACH_R_state1 = false) {} else \
for (auto && FOR_EACH_R_state2 = (c); \
!FOR_EACH_R_state1; FOR_EACH_R_state1 = true) \
for (auto i = FOR_EACH_R_state2.rbegin(); \
i != FOR_EACH_R_state2.rend(); ++i)
if (bool _FE_ANON(s1_) = false) {} else \
for (auto && _FE_ANON(s2_) = (c); \
!_FE_ANON(s1_); _FE_ANON(s1_) = true) \
for (auto i = _FE_ANON(s2_).rbegin(); \
i != _FE_ANON(s2_).rend(); ++i)
/*
* Similar to FOR_EACH but also allows client to specify a 'count' variable
......@@ -105,18 +105,18 @@
* }
*/
#define FOR_EACH_KV(k, v, c) \
if (unsigned int FOR_EACH_state1 = 0) {} else \
for (auto && FOR_EACH_state2 = (c); \
!FOR_EACH_state1; FOR_EACH_state1 = 1) \
for (auto FOR_EACH_state3 = FOR_EACH_state2.begin(); \
FOR_EACH_state3 != FOR_EACH_state2.end(); \
FOR_EACH_state1 == 2 \
? ((FOR_EACH_state1 = 0), ++FOR_EACH_state3) \
: (FOR_EACH_state3 = FOR_EACH_state2.end())) \
for (auto &k = FOR_EACH_state3->first; \
!FOR_EACH_state1; ++FOR_EACH_state1) \
for (auto &v = FOR_EACH_state3->second; \
!FOR_EACH_state1; ++FOR_EACH_state1)
if (unsigned int _FE_ANON(s1_) = 0) {} else \
for (auto && _FE_ANON(s2_) = (c); \
!_FE_ANON(s1_); _FE_ANON(s1_) = 1) \
for (auto _FE_ANON(s3_) = _FE_ANON(s2_).begin(); \
_FE_ANON(s3_) != _FE_ANON(s2_).end(); \
_FE_ANON(s1_) == 2 \
? ((_FE_ANON(s1_) = 0), ++_FE_ANON(s3_)) \
: (_FE_ANON(s3_) = _FE_ANON(s2_).end())) \
for (auto &k = _FE_ANON(s3_)->first; \
!_FE_ANON(s1_); ++_FE_ANON(s1_)) \
for (auto &v = _FE_ANON(s3_)->second; \
!_FE_ANON(s1_); ++_FE_ANON(s1_))
namespace folly { namespace detail {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment