Opened 12 years ago
Closed 12 years ago
#4191 closed Patches (fixed)
c++ library using regex included in objective-c needs rename of variable id
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | Boost 1.43.0 | Component: | asio |
Version: | Boost 1.42.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Hey,
I'm using a c++ lib containing a lot of boost stuff in a cocoa application and for this have to make it run in the "objective-c++"-hybrid. To compile this, there has to be some little variables, all called "id" be renamed in the files regex/v4/basic_regex_creator.hpp regex/v4/perl_matcher_common.hpp
To test this: just include the header in a *.mm file and compile it with gcc -objc. By now, I've just recognized these two files using the reserved "id" as variable name.
Many many thanks in advance
Attachments (2)
Change History (18)
by , 12 years ago
Attachment: | patch_perl_matcher_common.patch added |
---|
by , 12 years ago
Attachment: | patch_basic_regex_creator.patch added |
---|
comment:1 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
I use FSF's gcc-4.2.4 objc++ compiler and, as opposed to Apple's compiler, this one also chokes on variables / template params with the name 'Protocol'. A simple workaround so far is to redefine these before including boost, but it's quite a mess. Would it be viable to change all instances of Protocol (and presumably protocol) also ;)?
In any case, I can imagine someone coming across the same issue, the work-around is as follows:
#define id cpp_id #define Protocol cpp_Protocol #include <boost/asio.hpp> #undef id #undef Protocol
comment:3 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:4 by , 12 years ago
Component: | regex → asio |
---|---|
Owner: | changed from | to
Status: | reopened → new |
Re-opening and re-assigning to Asio as that's the library affected in this new case.
I have a suspicion that the answer to this one may be "won't fix" though - "protocol" is just such a heavily used name - and frankly why not!
John.
comment:5 by , 12 years ago
follow-up: 7 comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [66173]) Merge from trunk. ........
r66075 | chris_kohlhoff | 2010-10-18 23:27:12 +1100 (Mon, 18 Oct 2010) | 2 lines
Fix unused parameter warnings.
........
r66143 | chris_kohlhoff | 2010-10-22 23:07:36 +1100 (Fri, 22 Oct 2010) | 2 lines
Redefine Protocol and id to avoid clashing with Objective-C++ keywords. Fixes #4191.
........
r66144 | chris_kohlhoff | 2010-10-22 23:20:52 +1100 (Fri, 22 Oct 2010) | 2 lines
Version check not required.
........
r66156 | chris_kohlhoff | 2010-10-24 11:26:10 +1100 (Sun, 24 Oct 2010) | 2 lines
Fix for IBM C++ compiler.
........
r66158 | chris_kohlhoff | 2010-10-24 13:06:46 +1100 (Sun, 24 Oct 2010) | 2 lines
Fix vector reallocation performance problem. Fixes #4780.
........
r66159 | chris_kohlhoff | 2010-10-24 18:58:23 +1100 (Sun, 24 Oct 2010) | 2 lines
Fix kqueue_reactor so that it compiles on NetBSD. Fixes #4662.
........
r66162 | chris_kohlhoff | 2010-10-25 00:15:46 +1100 (Mon, 25 Oct 2010) | 2 lines
Fix failure in socket_base test on NetBSD.
........
follow-up: 9 comment:7 by , 12 years ago
Comments for r66143
Protocol and id are not macros,
so they should be #undef'ed in detail/pop_options.hpp:
# if defined(__OBJC__) # undef Protocol # pragma pop_macro("Protocol") # undef id # pragma pop_macro("id") # endif
comment:8 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
follow-up: 10 comment:9 by , 12 years ago
Replying to anonymous:
Comments for r66143
Protocol and id are not macros,
so they should be #undef'ed in detail/pop_options.hpp:# if defined(__OBJC__) # undef Protocol # pragma pop_macro("Protocol") # undef id # pragma pop_macro("id") # endif
AFAIK, they are macros as far as pop_macro is concerned. If you see a problem then please provide a test case.
The following source file "test.mm":
#include <boost/asio.hpp> #ifdef Protocol # error Protocol is defined #endif #ifdef id # error id is defined #endif
compiles without error or warning using gcc 4.4.5.
follow-up: 11 comment:10 by , 12 years ago
Replying to chris_kohlhoff:
AFAIK, they are macros as far as pop_macro is concerned. If you see a problem then please provide a test case.
With your "test.mm" (tested using gcc 4.0, 4.2, 4.4 on Mac OS X 10.5),
warnings ("warning: ignoring #pragma pop_macro", "warning: ignoring #pragma pop_macro") and
errors ("error: #error Protocol is defined", "error: #error id is defined") are emitted.
As a side note, this only happens on the trunk and NOT on the Boost 1.44.
follow-up: 12 comment:11 by , 12 years ago
Sorry, in the above comment, there is a typo:
warnings ("warning: ignoring #pragma pop_macro", "warning: ignoring #pragma pop_macro")
-->
warnings ("warning: ignoring #pragma push_macro", "warning: ignoring #pragma pop_macro")
In Objective-C++, "id" is a typedef and not a macro.
So unless the user #define's "id",
'#pragma push_macro("id")' in push_options.hpp and
'#pragma pop_macro("id")' in pop_options.hpp do not make any effect,
and thus the macro '#define id cpp_id' in push_options.hpp is still valid after pop_macro.
Ditto for "Protocol".
follow-up: 14 comment:12 by , 12 years ago
Replying to anonymous:
So unless the user #define's "id", '#pragma push_macro("id")' in push_options.hpp and '#pragma pop_macro("id")' in pop_options.hpp do not make any effect, and thus the macro '#define id cpp_id' in push_options.hpp is still valid after pop_macro.
This was wrong; This happened simply because the pragmas push_macro and pop_macro are not implemented on the tested compilers. After updating gcc from 4.4.1 (MacPorts) to 4.4.5 (MacPorts), "test.mm" gets successfully compiled with r66143. However, with r66289, compiling "test.mm" using MacPorts gcc 4.4.5 fails again (see below).
Comments about r66289,
MacPorts gcc's are non-apple compilers, but they seem to have __APPLE_CC__ macros.
While __APPLE_CC__ is defined as 1 in MacPorts gcc's,
Apple gcc's define __APPLE_CC__ as the build numbers (e.g. 5488 and 5564).
So it might be better to use
!(defined(__APPLE_CC__) && __APPLE_CC__ > 1)
for detecting non-Apple compilers.
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Fixed in r66398.
Chris, great thanks for your work!
comment:15 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Not closing until merged to release.
comment:16 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [66554]) Merged objective c++ fix from tunk. Fixes #4191.
........
r66289 | chris_kohlhoff | 2010-10-31 09:45:29 +1100 (Sun, 31 Oct 2010) | 4 lines
Target workaround at non-Apple objective-c++ compilers only, as the previous workaround broke those platforms. Pragmas push_macro and pop_macro are only available on gcc 4.4 or later, so use plain ol' #define/#undef instead.
........
r66398 | chris_kohlhoff | 2010-11-04 22:40:42 +1100 (Thu, 04 Nov 2010) | 2 lines
MacPorts gcc also defines APPLE_CC, but to 1.
........
(In [61789]) Change "id" to "idx" to be Objective C++ compatible. Fixes #2306. Fixes #4132. Fixes #4191.