C++0x:VC10编译器的bug

 
Visual Studio 2010 的 C++ 编译器(VC10)支持六项C++0x新特性:auto、右值引用、static_assert、nullptr、lambda表达式以及decltype。与同样在标准出台之前诞生的VC6相比较,在与标准的契合度这一点上VC10显然有了巨大的进步,但遗憾的是,在功能增强的同时编译器自身也不可避免地引入了不少bug,尤其是关于lambda表达式,下面略举几例。
 
1.
编译器报错:error C3861: 'X': identifier not found.
规避方案(奇怪)如下:
2.
编译器报错:error C2653: 'dummy_type' : is not a class or namespace name.
                 error C3861: 'foo': identifier not found.
规避方案(奇妙)如下:
3.
编译器直接崩溃:fatal error C1001: An internal error has occurred in the compiler.
规避方案(正常)如下:
4.
编译器报错:error C3493: 'A' cannot be implicitly captured because no default capture mode has been specified.
规避方案(可疑)如下:
5.
编译器再一次崩溃:fatal error C1001: An internal error has occurred in the compiler.
综合利用以上学到的“知识”,不难得出以下规避方案:
 
注:以上“有问题”的代码在gcc4.5中均能编译通过。
注:部分代码摘自StackOverflow: Are function-local typedefs visible inside C++0x lambdas?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值