Opened 11 years ago
Closed 7 years ago
#6616 closed Bugs (fixed)
boost preprocessor bug in 1.49
Reported by: | Owned by: | No-Maintainer | |
---|---|---|---|
Milestone: | To Be Determined | Component: | preprocessor |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | Cc: |
Description
this example work incorrect with boost 1.49 on g++ 4.61 with compile flags -std=gnu++0x
#define WRITE_TEST_VALUE(r, data, num, name) std::cout << ", num: " << num << ", name: " << BOOST_PP_STRINGIZE(name);
#define ON_FOREACH_ARGS(ArgsArray, Functor) \
BOOST_PP_LIST_FOR_EACH_I(Functor, , \
BOOST_PP_TUPLE_TO_LIST(BOOST_PP_ARRAY_SIZE(ArgsArray), BOOST_PP_ARRAY_DATA(ArgsArray)))
#define TEST_PP_LIST_FOREACH(ArgsArray) \
std::cout << " sz: " << BOOST_PP_ARRAY_SIZE(ArgsArray); \
ON_FOREACH_ARGS(ArgsArray, WRITE_TEST_VALUE)
#include <iostream>
#include <boost/preprocessor/list.hpp>
#include <boost/preprocessor/tuple.hpp>
#include <boost/preprocessor/array.hpp>
#include <boost/preprocessor/stringize.hpp>
int main()
{
std::cout << "0:" << std::endl;
TEST_PP_LIST_FOREACH((0, ()))
std::cout << std::endl << "1:" << std::endl;
TEST_PP_LIST_FOREACH((1, (bla)))
std::cout << std::endl << "2:" << std::endl;
TEST_PP_LIST_FOREACH((2, (nu, bla)))
std::cout << std::endl;
return 0;
}
output:
g++ test_pp.cpp -I/home/snike/boost/boost_1_49_0
./a.out
0:
sz: 0
1:
sz: 1, num: 0, name: bla
2:
sz: 2, num: 0, name: nu, num: 1, name: bla
output2:
g++ test_pp.cpp -I/home/snike/boost/boost_1_49_0 -std=gnu++0x
./a.out
0:
sz: 0, num: 0, name:
1:
sz: 1, num: 0, name: bla
2:
sz: 2, num: 0, name: nu, num: 1, name: bla
on boost 1.48 this example work correctly
Change History (4)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
These problems are related to this ticket: https://svn.boost.org/trac/boost/ticket/7560
comment:3 by , 7 years ago
There is no such thing as a tuple of size 0. Therefore attempting to pass 0 for a tuple size gives undefined behavior.
comment:4 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Yes, the boost preprocessor library changed behavior from 1.48.0 to 1.49.0.
For Visual C++ 8.0, preprocessing this code:
used to give this output:
but for 1.49.0 the compiler give these warnings:
a.cpp(5) : warning C4003: not enough actual parameters for macro 'BOOST_PP_TUPLE_TO_LIST_1' a.cpp(5) : warning C4003: not enough actual parameters for macro 'BOOST_PP_TUPLE_TO_LIST_1'
and this output:
I have similar problems for BOOST_PP_TUPLE_TO_SEQ() and for Clang 3.1. These problems still exist for the latest version of boost (1.52.0).