Opened 13 years ago

Closed 7 years ago

#4090 closed Bugs (fixed)

Macroses BOOST_PP_SEQ_FOR_EACH_*R are not reenterable

Reported by: Andrey <andry@…> Owned by: No-Maintainer
Milestone: Component: preprocessor
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:

Description

Sample: #define MY_SEQ (1)(12)(123)

#define GENERATOR_2(r,data,i,elem) i

#define GENERATOR_1(r,data,i,elem) BOOST_PP_SEQ_FOR_EACH_I_R(r,GENERATOR_2,*,MY_SEQ)

#define GENERATE() BOOST_PP_SEQ_FOR_EACH_I(GENERATOR_1,*,MY_SEQ)

GENERATE()

Visual Studio 2005 SP1 compiler raise error: error C2065: 'GENERATOR_2' : undeclared identifier

Change History (2)

comment:1 by Edward Diener, 7 years ago

First off you are not using BOOST_PP_SEQ_FOR_EACH but BOOST_PP_SEQ_FOR_EACH_I. BOOST_PP_SEQ_FOR_EACH_I is not re-entrant to BOOST_PP_SEQ_FOR_EACH_I, for obvious reasons ( you are calling back to the same macro in the expansion of a macro and the C++ preprocessor is not re-entrant in that way ). BOOST_PP_SEQ_FOR_EACH_I is not re-entrant to BOOST_PP_SEQ_FOR_EACH_I_R, which is what you are doing above, because both share the same code for the internal BOOST_PP_FOR invocation as far as the pred, op, and macro code is concerned.

The documentation for BOOST_PP_SEQ_FOR_EACH_I_R says that "It reenters BOOST_PP_FOR with maximum efficiency". That does not mean that it itself can be called from BOOST_PP_SEQ_FOR_EACH_I. It can't for the reason stated above.

comment:2 by Edward Diener, 7 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.