Modify

Opened 8 years ago

Closed 7 years ago

#4191 closed Patches (fixed)

c++ library using regex included in objective-c needs rename of variable id

Reported by: lydisworld@… 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)

patch_perl_matcher_common.patch (807 bytes) - added by anonymous 8 years ago.
patch_basic_regex_creator.patch (2.1 KB) - added by anonymous 8 years ago.

Download all attachments as: .zip

Change History (18)

Changed 8 years ago by anonymous

Changed 8 years ago by anonymous

comment:1 Changed 8 years ago by John Maddock

Resolution: fixed
Status: newclosed

(In [61789]) Change "id" to "idx" to be Objective C++ compatible. Fixes #2306. Fixes #4132. Fixes #4191.

comment:2 Changed 7 years ago by anonymous

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 Changed 7 years ago by John Maddock

Resolution: fixed
Status: closedreopened

comment:4 Changed 7 years ago by John Maddock

Component: regexasio
Owner: changed from John Maddock to chris_kohlhoff
Status: reopenednew

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 Changed 7 years ago by chris_kohlhoff

(In [66143]) Redefine Protocol and id to avoid clashing with Objective-C++ keywords. Refs #4191.

comment:6 Changed 7 years ago by chris_kohlhoff

Resolution: fixed
Status: newclosed

(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.

........

comment:7 in reply to:  6 ; Changed 7 years ago by 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

comment:8 Changed 7 years ago by anonymous

Resolution: fixed
Status: closedreopened

comment:9 in reply to:  7 ; Changed 7 years ago by chris_kohlhoff

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.

comment:10 in reply to:  9 ; Changed 7 years ago by anonymous

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.

comment:11 in reply to:  10 ; Changed 7 years ago by anonymous

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".

comment:12 in reply to:  11 ; Changed 7 years ago by anonymous

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:13 Changed 7 years ago by chris_kohlhoff

Please try [66398].

comment:14 in reply to:  12 Changed 7 years ago by anonymous

Resolution: fixed
Status: reopenedclosed

Fixed in r66398.

Chris, great thanks for your work!

comment:15 Changed 7 years ago by chris_kohlhoff

Resolution: fixed
Status: closedreopened

Not closing until merged to release.

comment:16 Changed 7 years ago by chris_kohlhoff

Resolution: fixed
Status: reopenedclosed

(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.

........

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain chris_kohlhoff.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.