主流编译器对C++11的支持现状比较

来源:互联网 发布:华资软件技术有限公司 编辑:程序博客网 时间:2024/06/14 07:49
摘要:C++11标准正式发布已有一段时日,但想要真正普及还需要编译器的支持,那各主流C++编译器对其支持实现得如何?本文比较了GCC 4.8、Clang 3.3、Visual Studio 2012以及Intel C++编译器V.13.0,值得C++开发者们留意。

GCC 4.8刚刚发布,Clang 3.3也发布在即,如果你使用Visual Studio 2012,也可以通过安装一个实验性的CTP更新(VS2012 Nov CTP)来获取额外的C++11支持;除此之外,这里还比较了Intel C++编译器v.13.0,不过这仍然是一个预览版。

特性VS2012
Nov CTPg++ 4.8Clang 3.3Intel 13.0autoYesYesYesYesdecltypeYesYesYesYesRvalue references and move semanticsYesYesYesYesLambda expressionsYesYesYesYesnullptrYesYesYesYesstatic_assertYesYesYesYesRange based for loopYesYesYesYesTrailing return type in functionsYesYesYesYesextern templatesYesYesYesYes>> for nested templatesYesYesYesYesLocal and unnamed types as template argumentsYesYesYesYesVariadic macrosYesYesYesYesVariadic templatesYesYesYesYesDefault template arguments in function templatesYesYesYesYesfinal method keywordYesYesYesNooverride method keywordYesYesYesNoStrongly typed enumsYesYesYesPartialForward declared enumsYesYesYesPartialInitializer listsYesYesYesPartialexplicit type conversion operatorsYesYesYesNoRaw string literalsYesYesYesNoForwarding constructorsYesYesYesNoTemplate aliasesNoYesYesYesDefaulted methodsNoYesYesYesDeleted methodsNoYesYesYesNew built-in typesPartialYesYesPartialAlignment supportPartialYesYesNoInline namespacesNoYesYesNosizeof on non-static data members without an instanceNoYesYesNoChanged restrictions on union membersNoYesYesNoUser defined literalsNoYesYesNoEncoding support in literalsNoYesYesNoArbitrary expressions in template deduction contextsNoYesYesDon’t knowNon-static data member initializersNoYesYesDon’t knownoexceptNoYesYesPartialconstexprNoYesYesPartialC99 compatibilityPartialYesPartialYesGeneralized attributesNoYesPartialYesThread local storagePartialYesNoPartialInheriting constructorsNoYesNoNoRvalue references for *thisNoNoYesNoMinimal support for garbage collectionYesNoNoDon’t know

从表格数据我们可以看到,GCC正在取代Clang成为C++11支持最佳的编译器,而Visual Studio在对C++11特性的支持上也有明显的改进,特别是新增对variadic templates、 initializer lists以及raw literals的支持。当然这些支持中那些属于完全支持,哪些是无bug的支持不得而知,需要开发者自己去体验。

除了C++11特性之外,对其类库的支持同样需要的到重视,但下表中不会标注各编译器支持与标准库之间的细小差别。

  • 微软的库并没有实现那些需要尚未被实现的语言功能支持的东西,例如 constexpr(在Visual Studio 2012最初的发行版中)。库文件并没有为支持2012年11月CTP中使用的特性——如 initializer list(初始化列表)和variadic template(可变参数模板)——而更新
  • GCC libstdc++有点滞后,因为它不支持正则表达式以及低级并行特性,此外,在很多情况下也没有实现constexpr方法。
  • Clang对libc++的支持在Mac OS上非常完美,但部分功能尚未在Windows和Linux下实现。

特性MSVClibstdc++libc++Concurrency: async/future/promise/packaged_taskYesYesYesConcurrency: thread and relatedYesYesYesConcurrency: condition variablesYesYesYesConcurrency: mutexesYesYesYesConcurrency: atomic types and operationsYesYesYesConcurrency: relaxed memory ordering and fencesYesNoYesSmart pointersYesYesYesTuplesYesYesYesstd::bindYesYesYesstd::functionYesYesYesRegular expressionsYesNoYesType traitsYesPartialYesstd::forward_listYesYesYesstd::arrayYesYesYesHash tablesYesYesYesRandom number generationYesYesYesCompile time rational numbers (ratio)YesYesYesTime utilities (chrono)YesYesYesInitializer listsYesYesYesDiagnostics (system_error)YesYesYesSTL refinements and new algorithmsYesYesYesGeneral purpose (move, forward, declval etc.)YesYesYes

可以看到,C++及其类库的支持已经大有提升,Clang和GCC几乎已经为C++11提供了完整的支持;Visual Studio也增强了对C++11的支持;同时Intel的编译器对C++11的支持大幅提升。

相信到明年,各主流编译器应该都能够完全支持C++11标准。

0 0
原创粉丝点击