Ticket #2069 (closed Bugs: fixed)

Opened 9 years ago

Last modified 3 years ago

#elif behaviour in gcc 4.4

Reported by: tim blechmann <tim@…> Owned by: danieljames
Milestone: Boost 1.37.0 Component: mpl
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc: daniel@…, rwgk@…


hi all,

currently, the mpl header do not compile with gcc-4.4

a small patch is attached


boost_mpl_gcc-4_4.patch Download (2.5 KB) - added by tim blechmann <tim@…> 9 years ago.
mpl.patch Download (3.9 KB) - added by danieljames 9 years ago.
A better patch for this problem.
0001-boost.mpl-gcc-4.4-fixes.patch Download (15.6 KB) - added by tim blechmann <tim@…> 9 years ago.
patch against boost-1.36.0

Change History

Changed 9 years ago by tim blechmann <tim@…>

Changed 9 years ago by danieljames

A better patch for this problem.

comment:1 Changed 9 years ago by danieljames

  • Cc daniel@… added
  • Milestone changed from Boost 1.36.0 to Boost 1.37.0

The patch I just attached is more complete and calls BOOST_PP_ITERATION_DEPTH correctly. But this is a larger problem, so I've also written to the mailing list.

(I also changed the milestone to 1.37 because we shouldn't accept patches for unreleased compilers at this late stage).

Changed 9 years ago by tim blechmann <tim@…>

patch against boost-1.36.0

comment:2 Changed 9 years ago by danieljames

  • Owner changed from agurtovoy to no-maintainer
  • Component changed from mpl to preprocessor
  • Summary changed from compile mpl with gcc-4.4 to #elif behaviour in gcc 4.4

The following is copied from:

A recent change to the development version of the gcc preprocessor changes the way it processes '#elif' directives and breaks a common use of the preprocessor library. We've already had reports of this causing problems in MPL, and it might also affect: variant, function_types, python, fusion, xpressive and phoenix. Details of the change are at:

With this change, the argument to an '#elif' directive is processed even if a previous '#if'/'#elif' directive was true. This causes the example use of BOOST_PP_ITERATION_DEPTH to break:

In this example, the first time the header is included, BOOST_PP_ITERATION_DEPTH is not yet defined, so it causes the develoment gcc to fail when the #elif directives are evaluated (which are skipped with existing versions, because the first #if directive evaluates to true).

Looking at the standard, I think their interpretation is correct (although I'm not familiar with it and could be missing something) but it isn't clear that this was the intent of the authors. Any opinions on this?

I think it's quite easy to work around, we can replace:

// .... 
// .... 
// .... 


// .... 
// .... 
// .... 
# endif 

So that the calls to BOOST_PP_ITERATION_DEPTH are skipped - or we could just include the necessary header before including the file. But it does seem a pity that any code which uses this technique might need to be changed for gcc 4.4. We should probably write to them about this (it doesn't look like they realised this would be a problem), but I'm writing here first in case anyone has any ideas.

comment:3 Changed 9 years ago by rwgk

  • Cc rwgk@… added

comment:4 Changed 9 years ago by rwgk

Is anyone working on this issue?

gcc 4.4 is in stage 3 now, and it looks like the new behavior will make it into the release.

comment:5 Changed 9 years ago by danieljames

  • Owner changed from no-maintainer to danieljames
  • Status changed from new to assigned

No, no one's working on it. Someone said they were going to write to Paul Mensonides but I guess that didn't work out, so it looks like it's up to me.

comment:6 Changed 9 years ago by rwgk

I just wrote a small Python script to do most of the work automatically. With this I got Boost.Python to compile with gcc 4.4. The script and the diffs against the current trunk are here:

Files and diffs_r48789_2008_09_15_1159.

I'll run these changes through our in-house multi-platform build+testing procedure.

I'm not setup for running the standard boost unit tests, to exercise the changes not used by Boost.Python. Help with this would be great.


comment:7 Changed 9 years ago by danieljames

Oh very clever. I wish I'd seen that you'd done that before doing some of them manually. I'm feeling stupid now.

Your patch looks good. To be picky, the comments are a bit mismatched - you've put 'gcc 4.4 compatability' on the #else from the outer if statement and the #endif from the inner statement. That could be confusing and it should be easy to fix. I'd suggest something like:

// For gcc 4.4 compatability, we must include the
// BOOST_PP_ITERATION_DEPTH test inside an #else clause.

and at the end:


But feel free to do it however you want.

I'm not set up for testing Boost.Python, but I can test the other libraries - so it's very convenient can you can test it. Can you create a ticket for just the python changes (include a link to this ticket, ie. #2069), and I'll deal with the other libraries. function_types is a bit of a problem as I'm getting failures on gcc 4.3 and the code to be changed looks a little odd already.

Thanks for your help.

comment:8 Changed 9 years ago by rwgk

OK, I changed the Python script according to your suggestions, and I'm only applying the script to the mpl and python subdirectories. (I need the mpl patches for Boost.Python). I won't do anything with the other files since I'm not setup for the tests, but there aren't very many. Suggestion:

  • I try out the mpl and python fixes in our multi-platform build.
  • I pass them by David Abrahams for review.
  • Then I check them in.
  • Once that is settled (in a day or two) you work on the rest.

How does that sound? (You can easily run the script yourself to do most of the legwork for the rest. Let me know if you need more information.) Ralf

comment:9 Changed 9 years ago by danieljames

That's great, although I might not wait to deal with the other libraries. Thanks again.

comment:10 Changed 9 years ago by rwgk

In the meantime, I ran our multi-platform build+test with the modified boost sources, and there are no errors. I wrote David and Aleksey, pointing them to the diffs:

I'll wait until tomorrow afternoon for feedback, although it seems highly unlikely that there's something wrong with the diffs.

comment:11 Changed 9 years ago by rwgk

No feedback from David or Aleksey...

I went ahead and checked in my patches:

r48960 | rwgk | 2008-09-24 21:49:24 -0700 (Wed, 24 Sep 2008) | 1 line

boost/python, boost/mpl: gcc 4.4 compatibility (see ost/ticket/2069)

comment:12 follow-up: ↓ 13 Changed 8 years ago by danieljames

Sorry, I've been very slack. Here are the patches I've submitted: #2375, #2376, #2377, #2378, #2379.

I'll change the preprocessor library myself.

comment:13 in reply to: ↑ 12 Changed 8 years ago by rwgk

Replying to danieljames:

Sorry, I've been very slack. Here are the patches I've submitted: #2375, #2376, #2377, #2378, #2379.

Are you planning to check these patches in yourself?

comment:14 Changed 8 years ago by danieljames

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Component changed from preprocessor to mpl

I've finally got round to fully testing the patches and I discovered that the problem only effects the mpl library. It uses a complicated system to preprocess the header files in advance for compilers which have slow preprocessors, and this was preventing it from including the preprocessor library. In all the other libraries <boost/preprocessor/iteration/iterator.hpp> is included by the time the #elif is reached so the problem doesn't occur.

So, this really was an mpl bug and not a preprocessor bug. If you want to, you can problably revert the changes to python. I'm going to try to get python testing working so I can see if it works without the patch but that might take me a little while. Sorry for the hassle. I'm closing the ticket as your patch fixed the problem in mpl.

comment:15 Changed 8 years ago by danieljames

(In [49257]) Merge the mpl fixes for gcc 4.4. (But not the python ones). Refs #2069.

Merged revisions 48960 via svnmerge from


r48960 | rwgk | 2008-09-25 05:49:24 +0100 (Thu, 25 Sep 2008) | 1 line

boost/python, boost/mpl: gcc 4.4 compatibility (see


comment:16 Changed 3 years ago by albermg7

Thanks a lot for your changes DanielJames?. 5 years ago and I am gonna use your files to fix my boost version required to build Flexsus :D


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

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

Note: See TracTickets for help on using tickets.