From 1dee6ec97e5608698324284582257b68252881a6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 10 Nov 2016 16:50:45 -0800 Subject: [PATCH] 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 --- folly/Foreach.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/folly/Foreach.h b/folly/Foreach.h index 84663ef3..f95274f1 100644 --- a/folly/Foreach.h +++ b/folly/Foreach.h @@ -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 @@ -104,19 +104,19 @@ * cout << key << " " << value; * } */ -#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) +#define FOR_EACH_KV(k, v, c) \ + 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 { -- 2.34.1