[bind] bug when used together with function.hpp on BCB

BCB 6.4, Boost 1.31 (1.30.2 fails too). Following snippet fails to compile: ---------------------------------------- #include <boost/function.hpp> // remove and it will compile OK #define BOOST_MEM_FN_ENABLE_FASTCALL // or remove this and it will be OK #include <boost/bind.hpp> // or move <function.hpp> after <bind.hpp> and it will compile OK int main() { return 0; } ---------------------------------------- with error: [C++ Error] bind_mf_cc.hpp(20): E2316 'mf0_fastcall' is not a member of '_mfi' Full parser context Unit1.cpp(6): #include C:\boost\boost_1_31_0\boost/bind.hpp bind.hpp(44): namespace boost bind.hpp(1544): #include C:\boost\boost_1_31_0\boost/bind/bind_mf_cc.hpp [C++ Error] bind_mf_cc.hpp(20): E2040 Declaration terminated incorrectly Full parser context Unit1.cpp(6): #include C:\boost\boost_1_31_0\boost/bind.hpp bind.hpp(44): namespace boost bind.hpp(1544): #include C:\boost\boost_1_31_0\boost/bind/bind_mf_cc.hpp [C++ Error] bind.hpp(1577): E2190 Unexpected } Full parser context Unit1.cpp(6): #include C:\boost\boost_1_31_0\boost/bind.hpp When the #include <boost/function.hpp> is removed it compiles cleanly. The code compiles OK on Intel C++ so it seems to be caused by some strange interaction with Boost.Function. /Pavel

[Problem with <bind.hpp> and <function.h> on BCC 6.4] I found what;s the cause: <boost/mem_fn.hpp> is included by <function.hpp> and so if one writes: ---------------- #include <boost/function.hpp> #define BOOST_MEM_FN_ENABLE_FASTCALL #include <boost/bind.hpp> ---------------- it results with Bind using differently pre-processed <mem_fn.hpp> than it is expected. Bellow is solution to produce clean error message when this situation happens: ------- file boost/mem_fn.hpp -------------- 1. remove #pragma once 2. on its place put following text: // Since this header is included by <function.hpp>: if you define // any of following tags after that and then include <bind.hpp>, // compilation will fail with hard to understand message. // // The macros bellow are in order to give early and understandable // failure during precompilation. #ifdef BOOST_BIND_ENABLE_STDCALL # define BOOST_BIND_ENABLE_STDCALL_TAG #endif #ifdef BOOST_BIND_ENABLE_FASTCALL # define BOOST_BIND_ENABLE_FASTCALL_TAG #endif #ifdef BOOST_BIND_ENABLE_PASCA # define BOOST_BIND_ENABLE_PASCAL_TAG #endif 3. at the end of mem_fn.hpp put: ... #else // Check for multiple include with different calling conventions enabled. // See top of header for more details. #ifdef BOOST_BIND_ENABLE_STDCALL # ifndef BOOST_BIND_ENABLE_STDCALL_TAG # error <function.hpp> or other header using <mem_fn.hpp> was included before <bind.hpp>. Please include <bind.hpp> first. # endif #endif #ifdef BOOST_BIND_ENABLE_FASTCALL # ifndef BOOST_BIND_ENABLE_FASTCALL_TAG # error <function.hpp> or other header using <mem_fn.hpp> was included before <bind.hpp>. Please include <bind.hpp> first. # endif #endif #ifdef BOOST_BIND_ENABLE_PASCAL # ifndef BOOST_BIND_ENABLE_PASCAL_TAG # error <function.hpp> or other header using <mem_fn.hpp> was included before <bind.hpp>. Please include <bind.hpp> first. # endif #endif #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED ------------------------------------ /Pavel

On Wednesday 18 February 2004 06:23 am, Pavel Vozenilek wrote:
[Problem with <bind.hpp> and <function.h> on BCC 6.4]
I found what;s the cause: <boost/mem_fn.hpp> is included by <function.hpp> and so if one writes:
---------------- #include <boost/function.hpp> #define BOOST_MEM_FN_ENABLE_FASTCALL #include <boost/bind.hpp> ----------------
it results with Bind using differently pre-processed <mem_fn.hpp> than it is expected.
Bellow is solution to produce clean error message when this situation happens:
Thanks. Peter, can you commit this or something like it? Doug

Douglas Gregor wrote:
On Wednesday 18 February 2004 06:23 am, Pavel Vozenilek wrote:
[Problem with <bind.hpp> and <function.h> on BCC 6.4]
I found what;s the cause: <boost/mem_fn.hpp> is included by <function.hpp> and so if one writes:
---------------- #include <boost/function.hpp> #define BOOST_MEM_FN_ENABLE_FASTCALL #include <boost/bind.hpp> ----------------
it results with Bind using differently pre-processed <mem_fn.hpp> than it is expected.
Bellow is solution to produce clean error message when this situation happens:
Thanks. Peter, can you commit this or something like it?
I appreciate Pavel's taking the time to identify the problem, but I'm reluctant to commit his fix. The problem is not specific to BOOST_MEM_FN_ENABLE_FASTCALL; any Boost macro that affects code (and nearly all of them do) can cause a similar error when it's being inconsistently defined in one file and not in another, or in the middle of the includes, as in this case. Macros should be defined project-wide, with -D or in the project settings. I will, however, definitely mention this in the bind/mem_fn documentation. Several times. In bold. :-)

"Peter Dimov" <pdimov@mmltd.net> wrote [ function.hpp & bind.hpp together]
I'm reluctant to commit his fix.... ... I will, however, definitely mention this in the bind/mem_fn documentation. Several times. In bold. :-)
Its OK with me. /Pavel
participants (3)
-
Douglas Gregor
-
Pavel Vozenilek
-
Peter Dimov