C++20 的编译器支持

来自cppreference.com


* - 在版本号上停留可以查看注记 * 查看其他注记
DRnn - 在 "DR" 后的数字 nn 表示应用该缺陷报告的目标 C++ 修订版本,例如 DR20 → C++20。

[编辑]C++20 核心语言功能特性

C++20 功能特性

 
提案

 
GCC
Clang
MSVC
Apple Clang
EDG eccp
Intel C++
Nvidia HPC C++ (ex PGI)*
Nvidia nvcc
Cray
允许 lambda 捕获[=, this]P0409R28 6 19.22*10.0.0*5.1 2021.1 20.7 12.0 11.0
__VA_OPT__P0306R4
P1042R1
8 (部分)*
10 (部分)*
12
9 19.25*11.0.3*5.1 2021.1 20.7 12.0 11.0
指派初始化器  (FTM)*P0329R44.7 (部分)*
8
3.0 (部分)*
10
19.21*(部分)*5.1 2021.1 20.7 12.0 11.0
泛型 lambda 的模板形参列表  (FTM)*P0428R28 9 19.22*11.0.0*5.1 2021.1 20.7 12.0 11.0
位域的默认成员初始化器P0683R18 6 19.25*10.0.0*5.1 2021.1 20.7 12.0 11.0
类模板实参推导中的 intializer_list 构造函数 P0702R18 6 19.14*5.0 2021.1 20.7 12.0 11.0
const& 限定的成员指针 P0704R18 6 19.0 (2015)*10.0.0*5.1 2021.1 20.7 12.0 11.0
概念  (FTM)*P0734R05*
10
10 19.23*(部分)*
19.30*
12.0.0* (部分) 6.1 2023.1*20.11 12.0 11.0
不求值语境中的 lambdaP0315R49 13 (部分)*
14 (部分)*
17
19.28 (16.8)*13.1.6* (部分) 6.2 2023.1 (部分)
2024.0
20.7 12.0
三路比较运算符  (FTM)*P0515R310 8 (部分)
10
19.20*12.0.0*5.1 2021.1 20.7 12.0 11.0
DR11:简化隐式 lambda 捕获 P0588R18 19.24*5.1 2021.1 20.7 12.0
基于范围的 for 的初始化语句P0614R19 8 19.25*11.0.0*6.0 2021.7 20.11 12.0 11.0
可默认构造与可赋值的无状态 lambdaP0624R29 8 19.22*10.0.1*5.1 2021.1 20.7 12.0 11.0
预置特殊成员函数的类型不匹配 P0641R29 (部分)*8 19.0 (2015)*(部分)*10.0.1*5.1 2021.1 20.7 12.0 11.0
特化中的访问检查 P0692R18 (部分)
14
19.26*14.0.0*5.1 2021.1 20.7 12.0
ADL 与不可见的函数模板 P0846R09 9 19.21*11.0.3*5.1 2021.1 20.7 12.0 11.0
DR11:指定 constexpr 函数定义何时为常量求值所需要  (FTM)*P0859R05.2 (部分)*
9
8 19.27* (部分)*
19.31**
11.0.0*(部分) 12.0 11.0
属性 [[likely]][[unlikely]]P0479R59 12 19.26*13.0.0*5.1 2021.7 20.7 12.0
使 typename 更可选 P0634R39 16 19.29 (16.10)*16.0.0*5.1 2023.1 20.7 12.0
lambda 初始化捕获中的包展开  (FTM)*P0780R29 9 19.22*11.0.3*6.1 2021.7 20.11 12.0 11.0
属性 [[no_unique_address]]P0840R29 9 19.28 (16.9)**11.0.3*5.1 2021.1 20.7 12.0 11.0
条件性平凡的特殊成员函数  (FTM)*P0848R310 16 19.28 (16.8)*6.1 2021.7 20.11 12.0
DR17:放松结构化绑定定制点查找规则 P0961R18 8 19.20*10.0.1*5.1 2021.1 20.7 12.0 11.0
DR11:放松范围 for 循环定制点查找规则 P0962R18 8 19.25*11.0.0*5.1 2021.1 20.7 12.0 11.0
DR17:允许到可访问成员的结构化绑定 P0969R08 8 19.20*10.0.1*5.1 2021.1 20.7 12.0 11.0
销毁的 operator delete  (FTM)*P0722R39 6 19.27*10.0.0*6.1 2023.1 20.11 12.0 11.0
常量模板形参中的类类型 P0732R29 12 (部分) 19.26* (部分)*
19.28 (16.9)*
13.0.0* (部分) 6.2 2023.1 (部分) 21.3 12.0
弃用经由 [=] 隐式捕获thisP0806R29 7 19.22*10.0.1*5.1 20.7 12.0 11.0
explicit(bool)  (FTM)*P0892R29 9 19.24*11.0.3*5.1 2021.1 20.7 12.0 11.0
集成功能特性测试宏P0941R25 3.4 19.15* (部分)
19.20*
5.0 2021.1 20.7 12.0 11.0
禁止有用户声明构造函数的聚合体 P1008R19 8 19.20*10.0.1*5.1 2021.1 20.7 12.0 11.0
constexpr虚函数  (FTM)*P1064R09 9 19.28 (16.9)*11.0.3*5.1 2021.1 20.7 12.0 11.0
比较的一致性改进 P1120R010 8 (部分)
10
19.22*12.0.0*5.1 2023.1 20.7 12.0 11.0
char8_t  (FTM)*P0482R69 *19.22*10.0.0*5.1 2021.1 20.7 12.0 11.0
std::is_constant_evaluated()  (FTM)*P0595R29 9 19.25*11.0.3*5.1 19.1 21.1 12.0 11.0
constexpr 函数中的 try-catchP1002R19 8 19.25*10.0.1*5.1 2023.1 20.7 12.0 11.0
立即函数consteval)  (FTM)*P1073R310 (部分)*
11
11 (部分)
14 (部分)*
17
19.28 (16.8)*
(部分)*

19.29 (16.10)*
11.0.3* (部分)
15.0.0*
5.1 2021.1 20.7 12.0
嵌套内联命名空间P1094R29 8 19.27*10.0.1*5.1 2021.1 20.7 12.0 11.0
有约束声明的另一种方式 P1141R210 10 19.26* (部分)
19.28 (16.9)*
12.0.5*6.1 2023.1 20.11 12.0 11.0
有符号整数为补码 P1236R19 9 11.0.3*不适用2023.1*是*12.0 11.0
常量表达式中的 dynamic_cast 及多态 typeidP1327R110 9 19.28 (16.9)*11.0.3*5.1 2021.1 20.7 12.0 11.0
constexpr 内更改联合体的活跃成员  (FTM)*P1330R09 9 19.10*11.0.3*5.1 2021.1 20.7 12.0 11.0
协程  (FTM)*  (FTM)*P0912R5
LWG3393
10 8 (部分)
17 (部分)*
19.0 (2015)* (部分)
19.10**
19.28 (16.8)*
10.0.1* (部分) 5.1 2021.1 23.3*12.0 (host code only)
括号形式的聚合体初始化  (FTM)*P0960R310 16 19.28 (16.8)*16.0.0*5.1 2021.1 20.7 12.0
DR11:new 表达式中的数组大小推导 P1009R211 9 19.27*11.0.3*5.1 2021.1 20.7 12.0 11.0
模块  (FTM)*P1103R311 (部分) 8 (部分) 19.0 (2015)* (部分)
19.10**
19.28 (16.8)*
10.0.1* (部分) 2023.1 (部分)
更强的 Unicode 要求 P1041R4
P1139R2
10 19.0 (2015)**
19.26**
不适用2023.1*12.0 11.0
<=> != ==P1185R210 10 19.22*12.0.0*5.1 2021.1 20.7 12.0 11.0
DR11:拥有不同异常说明的显式默认化函数 P1286R210 9 19.28 (16.8)*11.0.3*5.1 2021.1 20.7 12.0 11.0
结构化绑定的 lambda 捕获与存储类说明符 P1091R3
P1381R1
10 8 (部分)
16
19.11**
19.24**
16.0.0*5.1 2021.1 20.7 12.0
容许转换到未知边界数组 P0388R410 14 19.27*14.0.0*6.0 2021.5 20.11 12.0
constexpr 容器操作  (FTM)*P0784R710 10 19.28 (16.9)*12.0.0*6.0 2021.5 20.11 12.0 11.0
弃用 volatile 的某些用法 P1152R410 10 19.27*12.0.0*6.0 2021.5 20.11 12.0 11.0
constinit  (FTM)*P1143R210 10 19.29 (16.10)*12.0.0*6.1 2021.7 20.11 12.0 11.0
弃用下标中的逗号运算符P1161R310 9 19.25*11.0.3*6.0 2021.7 20.11 12.0 11.0
带消息的 [[nodiscard]]P1301R410 9 19.25*11.0.3*6.0 2021.5 20.11 12.0 11.0
constexpr 函数中的平凡默认初始化 P1331R210 10 19.27*12.0.0*6.1 2021.7 20.11 12.0 11.0
constexpr 函数中的不求值 asm 声明 P1668R110 10 19.28 (16.9)*12.0.0*6.1 2021.7 20.11 12.0 11.0
using enum  (FTM)*P1099R511 13 19.24*13.1.6*6.3 2023.1 22.5 12.0
对指定的比较类别合成三路比较P1186R311 10 19.24*12.0.0*6.0 2021.5 20.11 12.0 11.0
DR17:构造函数的 [[nodiscard]]P1771R110 9 19.24*11.0.3*6.0 2021.5 20.11 12.0 11.0
别名模板的类模板实参推导  (FTM)*P1814R010 19 19.27*6.5 23.9 12.0
聚合类的类模板实参推导  (FTM)*P1816R0
P2082R1
10*
11*
17 19.27*6.3 2023.1 (部分)*
2024.1
23.3 12.0
DR11:更多局部对象与右值引用的隐式移动P1825R011*13 19.24*13.1.6*6.0 2021.5 20.11 12.0
允许默认化按值比较 P1946R010 10 19.25*12.0.0*6.1 2021.7 20.11 12.0 11.0
移除 std::weak_equalitystd::strong_equalityP1959R010 10 19.25*12.0.0*6.1 2021.7 20.11 12.0 11.0
常量模板形参的不一致  (FTM)*P1907R110 (部分)
11
18 (部分)*19.26*13.1.6* (部分) 6.2 2023.1 (部分) 21.3 12.0
DR98:伪析构函数终结对象生存期 P0593R611 11 12.0.5*不适用2023.1*12.0 11.0
DR11:应认为从 T*bool 的转换为窄化 P1957R210*
11*
11 19.27*12.0.5*6.1 12.0 11.0
 

C++20 功能特性
 

提案
GCC
Clang
MSVC
Apple Clang
EDG eccp
Intel C++
Nvidia HPC C++ (ex PGI)*
Nvidia nvcc
Cray

[编辑]C++20 库功能特性

C++20 功能特性

 
提案

 
GCC libstdc++
Clang libc++
MSVC STL
Apple Clang*
std::endian  (FTM)*P0463R18 7 19.22*10.0.0*
扩展 std::make_shared() 以支持数组  (FTM)*P0674R112 15 19.27*14.0.3*
原子浮点数类型  (FTM)*P0020R610 18 19.22*16.0.0*
同步缓冲std::basic_osyncstream)  (FTM)*P0053R711 18 19.29 (16.10)*
<algorithm><utility>constexpr  (FTM)*P0202R310 8 (部分)
12
19.26*10.0.1* (部分)
13.0.0*
<complex> 的更多 constexpr  (FTM)*P0415R19 7 (部分)
16
19.27*10.0.0* (部分)
15.0.0*
使 std::memory_order 为有作用域枚举 P0439R09 9 19.25*11.0.3*
字符串前缀后缀检查:string(_view) ::starts_with / ends_with  (FTM)*P0457R29 6 19.21*10.0.0*
operator<=> 的库支持 <compare>  (FTM)*P0768R110 7 (部分)
12 (部分)*
17
19.20* (部分)
19.28 (16.9)*
13.0.0*
std::remove_cvref  (FTM)*P0550R29 6 19.20*10.0.0*
标准库中的 [[nodiscard]]P0600R19 7 (部分)
16
19.13* (部分)
19.22*
10.0.0* (部分)
15.0.0*
数值算法使用 std::moveP0616R09 12 19.23*13.0.0*
转换指针为裸指针的工具  (FTM)*P0653R28 6 19.22*
原子 std::shared_ptrstd::weak_ptr  (FTM)*P0718R212 19.27*
std::span  (FTM)*P0122R710 7 19.26*10.0.0*
日历时区  (FTM)*P0355R711 (部分)*
13 (部分)*
14
7 (部分)
19 (部分)*
19.29 (16.10)*10.0.0* (部分)
<version>P0754R29 7 19.22*10.0.0*
比较无序容器 P0809R016.0*
常量表达式迭代器(ConstexprIterator) 要求  (FTM)*  (FTM)*P0858R09 12 19.11*13.0.0*
std::basic_string::reserve() 不应收缩 P0966R111 8 19.25*10.0.1*
带填充位的原子比较交换P0528R313 19.28 (16.8)*
std::atomic_ref  (FTM)*P0019R810 19 19.28 (16.8)*
关联容器的 contains() 成员函数,如 std::map::contains()P0458R29 13 19.21*13.1.6*
DR11:逐片构造的受保证复制消除 P0475R19 19.29 (16.10)*
std::bit_cast()  (FTM)*P0476R211 14 19.27*14.0.3*
2 的整数次幂运算

std::bit_ceil()std::bit_floor()std::bit_width()std::has_single_bit()  (FTM)*

P0556R3
P1956R1
9*
10*
9*
12*
19.25**
19.27**
19.28 (16.8)*
11.0.3**
13.0.0**
改进擦除式算法的返回值  (FTM)*P0646R19 10 19.21*12.0.0*
std::destroying_delete_t  (FTM)*P0722R39 9 19.27*11.0.3*
std::is_convertible  (FTM)*P0758R19 9 19.23*11.0.3*
添加 std::shift_left/right<algorithm>  (FTM)*P0769R210 12 19.21*13.0.0*
std::swap()swap 相关函数的 constexpr P0879R010 13 19.26*13.1.6*
std::type_identity  (FTM)*P0887R19 8 19.21*10.0.1*
概念库  (FTM)*P0898R310 13 19.23*13.1.6*
std::arrayconstexpr比较运算符P1023R010 8 19.27*10.0.1*
std::unwrap_ref_decaystd::unwrap_reference  (FTM)*P0318R19 8 19.21*10.0.1*
std::bind_front()  (FTM)*P0356R59 13 19.25*13.1.6*
不完整类型的 std::reference_wrapperP0357R39 8 19.26*10.0.1*
修正 operator>>(basic_istream&, CharT*)P0487R111 8 19.23*10.0.1*
char8_t 的库支持  (FTM)*P0482R69 8 (部分)
16
19.22*10.0.1* (部分)
15.0.0*
实现使用分配器构造工具函数P0591R49 16 19.29 (16.10)*15.0.0*
DR17:std::variantstd::optional 应传播复制/移动平凡性 P0602R48.3 8 19.11*10.0.1*
DR17:理智的 std::variant 转换构造函数 P0608R310 9 19.29 (16.10)**
19.42**
11.0.3*
std::function 的移动构造函数应为 noexceptP0771R17.2 6 19.22*
唯一范围提案  (FTM)*P0896R410 13 (部分)
15*
19.29 (16.10)*14.0.3*
无序关联容器的异质查找  (FTM)*P0919R3
P1690R1
11 12 19.23**
19.25**
13.0.0*
<chrono>zero()min()max() 应为 noexceptP0972R09 8 19.14*10.0.1*
std::pointer_traits 中的 constexpr  (FTM)*P1006R19 8 19.26*10.0.1*
std::assume_aligned()  (FTM)*P1007R39*
11
15 19.28 (16.9)*14.0.3*
使用默认初始化的智能指针创建(如 make_unique_for_overwrite)  (FTM)*P1020R1
P1973R1
11*
12*
16 19.28 (16.9)*15.0.0*
杂项 constexpr 小部分  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)*P1032R110 13 19.28 (16.8)*13.1.6*
移除 std::span 的比较运算符 P1085R210 8 19.26*10.0.1*
使 operator+(basic_string) 的有状态分配器传播更加一致 P1165R110 15 19.26*14.0.3*
一致容器擦除,如 std::erase(std::vector)std::erase_if(std::map)  (FTM)*P1209R0
P1115R3
9*
10*
8*
11*
19.25**
19.27**
10.0.1**
12.0.5**
标准库头文件单元 P1502R111 19.29 (16.10)*
polymorphic_allocator<> 作为词汇类型  (FTM)*P0339R69 16 19.28 (16.9)*15.0.0*
std::execution::unseq  (FTM)*P1001R29 17 19.28 (16.8)*
std::lerp()std::midpoint()  (FTM)*P0811R39 9 19.23* (部分)
19.28 (16.8)*
11.0.3*
std::span 的实用性增强 P1024R310 9*
14
19.26*11.0.3*
DR17:使 std::create_directory() 自发 P1164R18.3 12 19.20*13.0.0*
std::ssize()std::span 的无符号长度  (FTM)*P1227R210 9 19.25*11.0.3*
有界无界数组特征  (FTM)*P1357R19 9 19.25*11.0.3*
std::to_array()  (FTM)*P0325R410 10 19.25*12.0.0*
std::basic_stringbuf 缓冲的有效访问 P0408R711 17 19.29 (16.10)*15.0.0*
布局兼容性指针可互转换性特征  (FTM)*  (FTM)*P0466R512 19.29 (16.10)**
位操作std::

rotl()rotr()countl_zero()countl_one()countr_zero()countr_one()popcount()  (FTM)*

P0553R49 9 19.25**
19.28 (16.8)*
11.0.3*
数学常数  (FTM)*P0631R810 11 19.25*12.0.5*
文本格式化  (FTM)*P0645R1013 14**
17
19.29 (16.10)*15.0.0*
std::stop_tokenstd::jthread  (FTM)*P0660R1010 17 (部分)*
20*
19.28 (16.9)*
constexprstd::allocator 及相关工具  (FTM)*P0784R710 12 19.29 (16.10)*13.0.0*
constexprstd::string  (FTM)*P0426R1
P1032R1
P0980R1
12 15 19.29 (16.10)*
19.30**
14.0.3*
constexprstd::vector  (FTM)*P1004R212 15 19.29 (16.10)*
19.30**
14.0.3*
输入范围适配器P1035R710 16 19.29 (16.10)*15.0.0*
constexprstd::invoke() 及相关工具 P1065R210 12 19.28 (16.8)*13.0.0*
原子等待与提醒、std::counting_semaphorestd::latchstd::barrier  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)*P1135R611 11 19.28 (16.9)*13.1.6*
std::source_location  (FTM)*P1208R611 15* (部分)
16
19.29 (16.10)*15.0.0*
添加 <=> 到标准库 P1614R210 14* (部分)
17* (部分)
19
19.29 (16.10)*13.1.6* (部分)
std::atomicstd::atomic_flagconstexpr 默认构造函数  (FTM)*P0883R210 13 19.26*13.1.6*
数值算法constexpr  (FTM)*P1645R110 12 19.26*13.0.0*
安全整数比较  (FTM)*P0586R210 13 19.27*13.1.6*
 

C++20 功能特性
 

提案
GCC libstdc++
Clang libc++
MSVC STL
Apple Clang*
close