【发布时间】:2023-01-27 23:59:27
【问题描述】:
following code 在主干 gcc 和 clang 中编译良好,但在 c++20 模式的 msvc 中失败:
template <typename T = int>
void f(void* ptr, T&& t = {}) {
if (ptr) {
f(nullptr);
}
}
与消息:
error C2672: 'f': no matching overloaded function found note: could be 'void f(void *,T &&)' note: 'void f(void *,T &&)': could not deduce template argument for 'T' note: 'f': function declaration must be available as none of the arguments depend on a template parameter适用于 c++17 模式的 msvc,因为
/permissive-仅在 c++20 之后默认可用。可以通过显式指定模板类型(即函数主体中的
f<T>(nullptr);)轻松修复 msvc c++20。按照标准谁是对的?我对 c++17 和 c++20 模式都感兴趣。即将到来的 c++23 会有什么变化吗?
【问题讨论】:
-
当打开和关闭
/permissive标志时,错误在 C++17 标准中来来去去同样顺利。
标签: c++ templates language-lawyer