views:

140

answers:

3

We are writing an application that compiles with both gcc and Visual C++. Some team members only use Visual C++/Windows, and others only use gcc/linux. Due to differences between compilers the build sometimes breaks. I have "fixed" several scenarios that lead to build breaks using compiler options to enable/disable warnings, but currently I am stuck with the ">>" used within C++ templates.

Visual Studio seems to have unilaterally extended the standard to include ">>" as a valid expression within templates (this is valid only in the proposed C++0x). But gcc does not accept this as a valid template. Now I am unable to find an option in Visual Studio to disallow ">>" or in gcc to allow ">>". How should I proceed?

Note: This question is about the double angle bracket, not the right shift operator.

+8  A: 

I would separate them to > >. That is what the current standards require; it is the most correct and portable code. As far as I'm aware, gcc won't even compile if the angle brackets are next to each other.

JoshD
Yes, my problem is that the team members using Visual Studio do not mind using ">>". This causes a build break.
Amit Kumar
Then you need to enforce a coding standard. sbi's suggestion sounds good. All coders need to write code that works for everyone. If they're breaking the build, they're doing it wrong!
JoshD
Visual Studio also allows not writting `typename` to refer to a type that is dependent within another template. What are you going to do there? The problem is simple, and the solution is also simple. Use standard C++ and not compiler extensions if you want portability. That or decide for a single compiler (Comeau will fit there) that is also really standard compliant.
David Rodríguez - dribeas
You may suggest the VS developers to periodically compile their code also with MinGW and fix the errors that come up.
Matteo Italia
@David, @Matteo What you say makes sense. However, we are working in a research environment, where unluckily research as opposed to software development takes the majority of the time. We are hard-pressed for time. Some of the programmers are starters, and the ideal situation would be to simplify their lives, before they complicate others'.
Amit Kumar
+5  A: 

GCC currently (since version 4.3) supports this via:

g++ --std=c++0x -o output file1.cpp file2.cpp ...

You have to explicitly specify that your source code is written in C++0x standard.

PC2st
The problem with this is that C++0x is experimental i.e. some features may be removed as the standard evolves. But probably this would be the approach I have to take.
Amit Kumar
@Amit Kumar: yes it is experimental but the `Right angle brackets` feature will exist forever.
PC2st
@PC2st: But `> >` will also continue to work forever, and has the additional advantage that it also works _now_. The problem with enabling C++0x extensions for GCC might be that this will make the GCC users introduce code that VC can't deal with. Sorry, but I don't like this suggestion. When you're doing cross platform stuff, you need to settle for what's available _and stable_ on all the platforms. C++1x isn't.
sbi
@Amit: Features won't be removed from it. It is feature complete, and the *only* changes they're doing from now on are minor bugfixes and changes in wording.
jalf
+1  A: 

The way to deal with such problems is to have Automatic Builds and Tests running around the clock, triggered by checkins. This is also referred to as Continuous Integration. When a build breaks or a test fails, you need to be able to lookup which checkin(s) lead to this and point a finger at the responsible developer(s).

See, for example, this answer for tools doing this across platforms.

sbi
We have automated builds and finger pointing courtesy Hudson but only run on Windows. Hopefully some day I will find time to implement it also to run using Cygwin/g++. But still compiler errors are much better.
Amit Kumar
@Amit: Have a look at [hudson](http://hudson-ci.org/), then. I have seen it (or helped to) setup from scratch to having something running within a few hours several times. Of the various CI tools I have seen this was by far the easiest to setup, especially across platforms. It should be very easy to setup (virtual) build slave machines using GCC and VC.
sbi
@sbi, as I said I already use Hudson. The link for cross-platform build tools was useful. Thanks.
Amit Kumar
@Amit: I'm sorry I overlooked you saying you're already using hudson. (That's what I get for answering on SO with four kids tugging at my sleeves...) So why don't you just setup a GCC build slave?
sbi