• Jim Meyering's avatar
    folly/Foreach.h: allow FOR_EACH to be nested with no shadowing · ba22e52f
    Jim Meyering authored
    Summary:
    Prior to this change, any nested use of FOR_EACH would
    induce a shadowed declaration for each of the two local
    state variables it declares.
    
    This makes the names of those variables __LINE__-dependent,
    so that there is no shadowing, as long as each nested use
    is on a different line.
    
    This also adds a new test that (prior to this change) would fail to
    compile with an option like -Werror=shadow-compatible-local.
    
    Since this change relies on cpp token concatenation, I have included
    The fix defines a new helper macro, _FE_ANON, to derive each new variable
    name. I wondered whether to do this for every other FOR_* macro here, but
    since so far, I have encountered more than 10 cases of nested FOR_EACH
    uses in a large corpus, but no nesting of any other FOR_* macro, I am
    content to do it only for this one.
    
    Reviewed By: yfeldblum
    
    Differential Revision: D3992956
    
    fbshipit-source-id: f26fba89bc661bb9d22747dec0acdcf8c648fb83
    ba22e52f
ForeachTest.cpp 3.76 KB