Share via


vs 2017 15.3 预览版c++17 特性

[原文发表地址] vs 2017 15.3 预览版c++17 特性

[原文发表时间] 2017/5/10

vs 2017 15.3 预览版 现在已经上线, 它涵盖了更新之后的C++ toolset (例如, 编译器,连接器以及库), 和之前vs 2015 的更新一样, 我们基本以类似的发布频率在VS 2017 的改动中添加了C++17 特性。 然而和vs2015的改动(包含了IDE和toolset 的改变)不同的是, vs2017 IDE 的更新更加频繁(我们称之为“小步快跑”)。这也是为什么这是第一次toolset 的更新 (称之为“ 基础更新“)。

下表所示是关于编译器模块。虽然你可以下载vs 2017 15.3 预览版1, 但是我们最新提交的一些新增模块只能在预览版2中生效了, 当然这个预览版2也将很快被发布。为了明确指出这些模块的集合,因此在预览版2(当下还没有发布) 中生效的这些模块将被标注为[P2]。

++03/11 Core Language Features Status Paper Notes
[Everything else] VS 2015 [A]
Two-phase name lookup Partial [twoPhase]
Expression SFINAE Partial N2634 [B]
C99 preprocessor Partial N1653 [C]
Extended integer types N/A N1988 [D]
C++14 Core Language Features Status Paper Notes
Avoiding/fusing allocations N/A N3664 [E]
Tweaked wording for contextual conversions VS 2013 N3323
Binary literals VS 2015 N3472
auto and decltype(auto) return types VS 2015 N3638
init-captures VS 2015 N3648
Generic lambdas VS 2015 N3649
Variable templates VS 2015.2 N3651
Extended constexpr VS 2017 N3652
NSDMIs for aggregates VS 2017 N3653
[[deprecated]] attribute VS 2015 N3760
Sized deallocation VS 2015 N3778
Digit separators VS 2015 N3781
C++17 Core Language Features Status Paper Notes
New rules for auto with braced-init-lists VS 2015 N3922 [14]
Terse static_assert VS 2017 N3928
typename in template template-parameters VS 2015 N4051 [14]
Removing trigraphs VS 2010 N4086 [14]
Nested namespace definitions VS 2015.3 N4230
Fixing qualification conversions No N4261
Attributes for namespaces and enumerators VS 2015 N4266 [14]
u8 character literals VS 2015 N4267 [14]
Allowing more non-type template args No N4268
Fold expressions No N4295
Removing some empty unary folds No P0036R0
Removing the register keyword VS 2017.3 P0001R1
Removing operator++ for bool VS 2017.3 P0002R1
Adding noexcept to the type system No P0012R1
Extended aggregate initialization No P0017R1
Capturing *this by value VS 2017.3 P0018R3
__has_include VS 2017.3 [P2] P0061R1 [14]
Rewording inheriting constructors No P0136R1
Direct-list-init of fixed enums from integers VS 2017.3 P0138R2
constexpr lambdas VS 2017.3 P0170R1
Generalized range-based for-loops VS 2017 P0184R0 [14]
[[fallthrough]] attribute VS 2017 P0188R1
[[nodiscard]] attribute VS 2017.3 P0189R1
[[maybe_unused]] attribute VS 2017.3 P0212R1
Hexfloat literals No P0245R1
Using attribute namespaces without repetition VS 2017.3 P0028R4
Over-aligned dynamic memory allocation No P0035R4
Template argument deduction for class templates No P0091R3
Declaring non-type template parameters with auto No P0127R2
Guaranteed copy elision VS 2017.3 P0135R1
Refining expression evaluation order No P0145R3
Structured bindings VS 2017.3 P0217R3
Ignoring unrecognized attributes No P0283R2
constexpr if-statements VS 2017.3 [P2] P0292R2 [F]
Selection statements with initializers VS 2017.3 [P2] P0305R1
Inline variables No P0386R2
Matching template template-parameters to compatible arguments No P0522R0
Removing dynamic-exception-specifications No P0003R5
Pack expansions in using-declarations No P0195R2

[A]除了动态异常说明之外, C++11 中被淘汰的那些模块大部分已经在C++17 中被移除。 注意到 c++17 18.4 [except.spec]/提到:” 非异常说明符throw() 已经被被淘汰(D,3) ”,也就说说非异常说明符noexcept(true)。” 但是vs2017 15.3 预览版目前考虑将throw() 替换为__declspec(nothrow)。

[twoPhase] 尽管vs2017 15.3 版本不支持two-Phase 字段查找, 但是编译器团队仍然在基于后台正在完成一些主要的功能。 对预览版2 而言, /permissive- 这个编译选项将会激活部分支持two-phase 字段的查找(这里部分粗略计算有60%)。 我们也会在后期发布一个详细的博客来阐述具体的细节。

[B] 尽管SFINAE 表达式是部分支持, 它基本已经覆盖完全了。在vs 2015.2 中,对于STL 后台而言是充分支持的, 而且SFINAE 表达式对于像boost之类的第三方库已经进行了进一步的缺陷修复。 目前存在的最大缺陷是: 当实现void_t/decltype SFINAE 表达式时, 需要使用特定的标签类型。

[C] 就可变参数宏的的工作范畴而言,C99 预处理目前仍是部分支持。 我们正在计划在标注为完成之前,检修预处理器。

[D] 允许拓展整型类型但是不要求这样做。对于Clang 和Gcc 编译器而言,我们将不会实现这项功能。

[E] allocations 的使用并没有进行严格的界限,当下,我们仍然选择暂不实现。

[F]支持 /std:C++14 警告C4984: ‘if constexpr’ is a C++17 language extension。这将会允许STL在函数实现内部 (将来)去使用 “if constexpr”。

[14] 这些特性已经是可用的,当然也支持 /std:C++14。

[P2] 这些特性已经被提交, 在vs2017.3预览版2 中将会可用。

下面是STL 模块的更新列表:

Status Std Paper Title Notes
missing C++17 P0604R0 Changing is_callable/result_of To is_invocable/invoke_result (Options A and B)
missing C++17 P0005R4 not_fn()
patch C++17 P0358R1 Fixes For not_fn()
missing C++17 P0618R0 Deprecating <codecvt>
missing C++17 P0521R0 Deprecating shared_ptr::unique()
missing C++17 P0174R2 Deprecating Vestigial Library Parts
missing C++17 P0003R5 Removing Dynamic Exception Specifications
missing C++17 P0302R1 Removing Allocator Support In std::function
missing C++17 P0433R2 Deduction Guides For The STL
missing C++17 P0607R0 Inline Variables For The STL (Options A and B2)
missing C++17 P0258R2 has_unique_object_representations
missing C++17 P0426R1 constexpr For char_traits
missing C++17 P0063R3 C11 Standard Library
missing C++17 P0033R1 Rewording enable_shared_from_this
missing C++17 P0414R2 shared_ptr<T[]>, shared_ptr<T[N]>
patch C++17 P0497R0 Fixing shared_ptr For Arrays
missing C++17 P0083R3 Splicing Maps And Sets
patch C++17 P0508R0 Clarifying insert_return_type
missing C++17 P0067R5 Elementary String Conversions
C++17 P0220R1 Library Fundamentals V1
missing C++17 <memory_resource>
patch C++17 P0337R0 Deleting polymorphic_allocator Assignment
missing C++17 P0030R1 hypot(x, y, z)
missing C++17 P0226R1 Mathematical Special Functions
missing C++17 P0024R2 Parallel Algorithms [G]
patch C++17 P0336R1 Renaming Parallel Execution Policies
patch C++17 P0394R4 Parallel Algorithms Should terminate() For Exceptions
patch C++17 P0452R1 Unifying <numeric> Parallel Algorithms
missing C++17 P0218R1 <filesystem>
patch C++17 P0219R1 Relative Paths For Filesystem
patch C++17 P0317R1 Directory Entry Caching For Filesystem
patch C++17 P0392R0 Supporting string_view In Filesystem Paths
patch C++17 P0430R2 Supporting Non-POSIX Filesystems
patch C++17 P0492R2 Resolving NB Comments For Filesystem
VS 2017.3 [P2] C++17 P0031R0 constexpr For <array> (Again) And <iterator>
VS 2017.3 [P2] C++17 P0084R2 Emplace Return Type
VS 2017.3 [P2] C++17 P0295R0 gcd(), lcm()
VS 2017.3 [P2] C++17 P0298R3 std::byte [H]
VS 2017.3 [P2] C++17 P0435R1 Overhauling common_type [14]
VS 2017.3 [P2] C++17 P0505R0 constexpr For <chrono> (Again)
VS 2017.3 [P2] C++17 P0548R1 Tweaking common_type And duration [14]
VS 2017.3 C++17 Boyer-Moore search()
VS 2017.3 C++17 P0040R3 Extending Memory Management Tools
VS 2017.3 C++17 P0152R1 atomic::is_always_lock_free
VS 2017.3 C++17 P0154R1 hardware_destructive_interference_size, etc.
VS 2017.3 C++17 P0156R2 Renaming Variadic lock_guard To scoped_lock
VS 2017.3 C++17 P0253R1 Fixing Searcher Return Types
VS 2017.3 C++17 P0403R1 UDLs For <string_view> (“meow”sv, etc.)
VS 2017.3 C++17 P0418R2 atomic compare_exchange memory_order Requirements [14]
VS 2017.3 C++17 P0513R0 Poisoning hash [14]
VS 2017.3 C++17 P0516R0 Marking shared_future Copying As noexcept [14]
VS 2017.3 C++17 P0517R0 Constructing future_error From future_errc [14]
VS 2017.3 C++17 P0558R1 Resolving atomic<T> Named Base Class Inconsistencies [I] [14]
VS 2017.3 C++17 P0599R1 noexcept hash [14]
VS 2017 C++17 <algorithm> sample()
VS 2017 C++17 <any>
VS 2017 C++17 <optional>
VS 2017 C++17 <string_view>
VS 2017 C++17 <tuple> apply()
VS 2017 C++17 P0032R3 Homogeneous Interface For variant/any/optional
VS 2017 C++17 P0077R2 is_callable, is_nothrow_callable
VS 2017 C++17 P0088R3 <variant>
VS 2017 C++17 P0163R0 shared_ptr::weak_type
VS 2017 C++17 P0209R2 make_from_tuple()
VS 2017 C++17 P0254R2 Integrating string_view And std::string
VS 2017 C++17 P0307R2 Making Optional Greater Equal Again
VS 2017 C++17 P0393R3 Making Variant Greater Equal
VS 2017 C++17 P0504R0 Revisiting in_place_t/in_place_type_t<T>/in_place_index_t<I>
VS 2017 C++17 P0510R0 Rejecting variants Of Nothing, Arrays, References, And Incomplete Types
VS 2015.3 C++17 P0025R1 clamp()
VS 2015.3 C++17 P0185R1 is_swappable, is_nothrow_swappable
VS 2015.3 C++17 P0272R1 Non-const basic_string::data()
VS 2015.2 C++17 N4387 Improving pair And tuple [14]
VS 2015.2 C++17 N4508 shared_mutex (Untimed) [14]
VS 2015.2 C++17 P0004R1 Removing Deprecated Iostreams Aliases [J]
VS 2015.2 C++17 P0006R0 Variable Templates For Type Traits (is_same_v, etc.) [14]
VS 2015.2 C++17 P0007R1 as_const() [14]
VS 2015.2 C++17 P0013R1 Logical Operator Type Traits (conjunction, etc.) [14]
VS 2015.2 C++17 P0074R0 owner_less<> [14]
VS 2015.2 C++17 P0092R1 <chrono> floor(), ceil(), round(), abs() [14]
VS 2015.2 C++17 P0156R0 Variadic lock_guard [14]
VS 2015 C++17 N3911 void_t [14]
VS 2015 C++17 N4089 Safe Conversions In unique_ptr<T[]> [14]
VS 2015 C++17 N4169 invoke() [14]
VS 2015 C++17 N4190 Removing auto_ptr, random_shuffle(), And Old <functional> Stuff [K]
VS 2015 C++17 N4258 noexcept Cleanups [14]
VS 2015 C++17 N4259 uncaught_exceptions() [14]
VS 2015 C++17 N4277 Trivially Copyable reference_wrapper [14]
VS 2015 C++17 N4279 insert_or_assign()/try_emplace() For map/unordered_map [14]
VS 2015 C++17 N4280 size(), empty(), data() [14]
VS 2015 C++17 N4366 Precisely Constraining unique_ptr Assignment [14]
VS 2015 C++17 N4389 bool_constant [14]
VS 2013 C++17 N4510 Supporting Incomplete Types In vector/list/forward_list [14]
N/A C++17 N4284 Contiguous Iterators
N/A C++17 P0175R1 Synopses For The C Library
N/A C++17 P0180R2 Reserving Namespaces For Future Standardization
N/A C++17 P0346R1 A <random> Nomenclature Tweak
N/A C++17 P0371R1 Discouraging memory_order_consume
N/A C++17 P0467R2 Requiring Forward Iterators In Parallel Algorithms
N/A C++17 P0502R0 Parallel Algorithms Should terminate() For Exceptions, Usually
N/A C++17 P0503R0 Correcting Library Usage Of “literal type”
N/A C++17 P0509R1 Updating “Restrictions on exception handling”
N/A C++17 P0518R1 Copying Trivially Copy Constructible Elements In Parallel Algorithms
N/A C++17 P0523R1 Relaxing Complexity Requirements Of Parallel Algorithms (General)
N/A C++17 P0574R1 Relaxing Complexity Requirements Of Parallel Algorithms (Specific)
N/A C++17 P0623R0 Final C++17 Parallel Algorithms Fixes

“missing” 和“patch”已经分组管理,这一份将不需加以说明。库V1版本的 基本问题已经被分割为独立的模块,标注为“…” 。 最后, “N/A“意味着不再进行句法规范化的修改, 对用户而言也不会衍生出新的模块。 例如,当我们实现了部分算法的时候, 我们将会遵循当下的规范。 为了进一步跟踪,P0394R4 (并行算法应该以抛出异常终止)对用户而言是非常重要的, 而且也是实施者需要去了解的。 然而P0502R0(并行算法应该以抛出异常终止,经常 )却不是这样的。(允许非标准的执行策略产生不同的行为)。

[G] for_each_n() 系列将会在预览版2中生效。

[H]/std:c++17 和/std:c++latest 支持std::byte, 它可以通过定义_HAS_STD_BYTE 为0 来关闭

[I] 除了atomic_meow() 和atomic_meow_explicit()的命名问题之外, 这个问题可以通过替换命名或者提供显式模板参数来修正。我们已经实现了P0558R1 中用户普遍使用的部分(解决了atomic<T> j基类明名不一致问题)

[J] /std:c++17 和/std”c++latest 移除了旧的输入输出流成员函数, 它们也可以通过定义_HAS_OLD_IOSTREAMS_MEMBERS 为1 来恢复。

[K] /std:c++17 和 /std:c++latest 移除了auto_ptr, random_shuffle() 以及一些旧的<functional>成员。 它们也可以通过定义_HAS_AUTO_PTR_ETC 为1 来恢复。

我们已经完成了29个LWG 问题的修复,并且做了一些后台场景的改进,我们这儿提到的将会更接近于vs 2017.3 的最终发布版本。

请尝试vs 2017 15.3 预览版, 当我们知道您的想法。 (请记住:您需要用/std:c++17 或者/std:c++latest 来编译才能激活C++17 的特性, 除过上面表格中标注[14]的之外 – 请记住[P2]只有在预览版2 之后才生效。) 你可以使用IDE 的报告一个问题来提交问题。 关于编译器和库函数的问题, 包含一个完整的测试用例是重要的。