开发者

How to set more strict compiling rules in VC when compile C++ template code

guys, I want VC has the same strict compile rules as GCC when it compiles the c++ template code. But I don't know how to set this in my VC9.0 (Visual Studio 2008).

For example, the following code is not allowed in GCC.

AutoPtr<RefCounted<Shape>> shape;

since ">>" is not allowed here, and gcc requests to add at least one space between ">>" .

AutoPtr< RefCounted<Shape> > shape;

VC w开发者_如何学Pythonill not treat this as a error. From my understanding, VC has a more loose restriction on template code compiling.

How do I add more restriction in VC to make it be a same rules as GCC?


You don't. :( MSVC++ simply handles templates incorrectly, and you have to be careful.


Note that your particular example isn't actually an error in C++0x, so MSVC2010 would actually be right to accept it. (It's still wrong on lots of other things, though, but it's gotten a bit better.)

You might even "cheat" and enable C++0x for your gcc compile to allow it; just be sure not to accidentally use C++0x stuff MSVC2008 (or MSVC2010!) can't support.


I wouldn't really call it an error- C++0x has this restriction lifted, so I'd get used to it. More importantly, Visual Studio is perfectly happy to accept C++03-compliant brackets with a space between, so I'd just use that and forget about it. There's no way to change the fact that Visual Studio's parser is not as specified in the Standard and this is the least significant way in which it is non-conformant.


Have you tried disabling Microsoft-specific extensions?


I respectfully disagree with GMan's statement: "MSVC++ simply handles templates incorrectly". Instead, I would say that both MSVC and GCC handle templates incorrectly, each in its own way :)

To deal with compiler specifics it's worth to maintain a set of some compile-time test modules. Also, modern build systems such as bjam can be configured to run a brief unit test right after project's compilation. So all you will have to do is to build your project from time to time with gcc toolset (and/or on non-windows platform) to make sure everything works as expected.

PS. down-votes are not mine :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜