219
iPhone_iPad_Mac_apple
Visual Studio, GCC, Clang, Intel 對 C++11 特性的支持一覽表
距離我上次對C++11支持的不同編譯器的比較已經有大半年了。這次我來根據這些預覽版的編譯器的文檔來看下它們是如何堆砌起來的。
GCC的下個版本是4.8,以及Clang即將到來的版本是3.3 。如果你使用Visual Studio 2012,你可以安裝2012年11月更新支持C++11額外特征的體驗版CTP。
|
頂 翻譯的不錯哦!
|
我也對V.13.0的Intel C++編譯器感到好奇,雖然它還不是預覽版並且我也找不到有關它的新特性的信息。我沒找到任何有關這個即將發行版本的編譯器的信息。
| Feature |
VS2012
Nov CTP |
g++ 4.8 |
Clang 3.3 |
Intel 13.0 |
| auto |
Yes |
Yes |
Yes |
Yes |
| decltype |
Yes |
Yes |
Yes |
Yes |
| Rvalue references and move semantics |
Yes |
Yes |
Yes |
Yes |
| Lambda expressions |
Yes |
Yes |
Yes |
Yes |
| nullptr |
Yes |
Yes |
Yes |
Yes |
| static_assert |
Yes |
Yes |
Yes |
Yes |
| Range based for loop |
Yes |
Yes |
Yes |
Yes |
| Trailing return type in functions |
Yes |
Yes |
Yes |
Yes |
| extern templates |
Yes |
Yes |
Yes |
Yes |
| >> for nested templates |
Yes |
Yes |
Yes |
Yes |
| Local and unnamed types as template arguments |
Yes |
Yes |
Yes |
Yes |
| Variadic macros |
Yes |
Yes |
Yes |
Yes |
| Variadic templates |
Yes |
Yes |
Yes |
Yes |
| Default template arguments in function templates |
Yes |
Yes |
Yes |
Yes |
| final method keyword |
Yes |
Yes |
Yes |
No |
| override method keyword |
Yes |
Yes |
Yes |
No |
| Strongly typed enums |
Yes |
Yes |
Yes |
Partial |
| Forward declared enums |
Yes |
Yes |
Yes |
Partial |
| Initializer lists |
Yes |
Yes |
Yes |
Partial |
| explicit type conversion operators |
Yes |
Yes |
Yes |
No |
| Raw string literals |
Yes |
Yes |
Yes |
No |
| Forwarding constructors |
Yes |
Yes |
Yes |
No |
| Template aliases |
No |
Yes |
Yes |
Yes |
| Defaulted methods |
No |
Yes |
Yes |
Yes |
| Deleted methods |
No |
Yes |
Yes |
Yes |
| New built-in types |
Partial |
Yes |
Yes |
Partial |
| Alignment support |
Partial |
Yes |
Yes |
No |
| Inline namespaces |
No |
Yes |
Yes |
No |
| sizeof on non-static data members without an instance |
No |
Yes |
Yes |
No |
| Changed restrictions on union members |
No |
Yes |
Yes |
No |
| User defined literals |
No |
Yes |
Yes |
No |
| Encoding support in literals |
No |
Yes |
Yes |
No |
| Arbitrary expressions in template deduction contexts |
No |
Yes |
Yes |
Don’t know |
| Non-static data member initializers |
No |
Yes |
Yes |
Don’t know |
| noexcept |
No |
Yes |
Yes |
Partial |
| constexpr |
No |
Yes |
Yes |
Partial |
| C99 compatibility |
Partial |
Yes |
Partial |
Yes |
| Generalized attributes |
No |
Yes |
Partial |
Yes |
| Thread local storage |
Partial |
Yes |
No |
Partial |
| Inheriting constructors |
No |
Yes |
No |
No |
| Rvalue references for *this |
No |
No |
Yes |
No |
| Minimal support for garbage collection |
Yes |
No |
No |
Don’t know |
看起來GCC正取代Clang成為最支持C++11的編譯器。Visual Studio已經增加了好幾個重要C++11特性,像變參模板,初始化器和原生字。
|
頂 翻譯的不錯哦!
|
我真的不能在一個更為細致的層麵去評論這些編譯器實現到底完成得怎樣,還有沒有bug。(除了VS2012——我在我的書(《C++11 Rocks》)裏詳細列出過VS2012最初版本的大量bug)。
看下庫的支持情況也是比較有用的。由於各編譯器對標準庫的支持都有較多小改動,我並不打算對此給出詳細的細節。我也打算在這次的比較中省略Intel的庫。
我可以說,這些庫的主要附件大多由第三方實現提供(隨後在下麵的表格中展現),盡管這是有各種各樣的警告。
|
頂 翻譯的不錯哦!
|
微軟的庫實現中沒有那些需求尚未被實現的語言功能的東西,例如 constexpr(如VS2012的最初發行版)。庫文件還沒有更新,以支持2012年11月在 CTP 提出的編譯器功能,如初始化列表和可變參數模板。
GCC 的 libstdc++ 也有些滯後,例如它並不支持正則表達式以及地稱並發功能。同樣,在很多情況下,它也沒有實現 constexpr 方法。
|
頂 翻譯的不錯哦!
|
Clang的libc++是100%兼容MacOS的,但是它有部分的特性還不兼容Windows和Linux。
| Feature |
MSVC |
libstdc++ |
libc++ |
| Concurrency: async/future/promise/packaged_task |
Yes |
Yes |
Yes |
| Concurrency: thread and related |
Yes |
Yes |
Yes |
| Concurrency: condition variables |
Yes |
Yes |
Yes |
| Concurrency: mutexes |
Yes |
Yes |
Yes |
| Concurrency: atomic types and operations |
Yes |
Yes |
Yes |
| Concurrency: relaxed memory ordering and fences |
Yes |
No |
Yes |
| Smart pointers |
Yes |
Yes |
Yes |
| Tuples |
Yes |
Yes |
Yes |
| std::bind |
Yes |
Yes |
Yes |
| std::function |
Yes |
Yes |
Yes |
| Regular expressions |
Yes |
No |
Yes |
| Type traits |
Yes |
Partial |
Yes |
| std::forward_list |
Yes |
Yes |
Yes |
| std::array |
Yes |
Yes |
Yes |
| Hash tables |
Yes |
Yes |
Yes |
| Random number generation |
Yes |
Yes |
Yes |
| Compile time rational numbers (ratio) |
Yes |
Yes |
Yes |
| Time utilities (chrono) |
Yes |
Yes |
Yes |
| Initializer lists |
Yes |
Yes |
Yes |
| Diagnostics (system_error) |
Yes |
Yes |
Yes |
| STL refinements and new algorithms |
Yes |
Yes |
Yes |
| General purpose (move, forward, declval etc.) |
Yes |
Yes |
Yes |
比較高興的是能看到語言和庫的支持在穩步改善。Clang和GCC距離完全支持C++11已經很近了。Visual Studio同樣在改善對C++11的支持,令我感到欣慰的是C++編譯器的更新都是在主分支上。這份Intel的編譯器特征支持列表也越來越多。
誰知道明年這4個編譯器會不會全部支持C++11的特征呢!
|
最後更新:2017-04-03 22:15:30