c++ - P0522R0的中断代码如何?

标签 c++ language-lawyer clang++ c++17

今天,我正在阅读clang的C++ 17支持页面。我注意到有些奇怪。将功能与模板模板参数匹配到兼容参数(P0522R0)标记为部分,因为必须通过开关将其激活。他们的注释says:

Despite being the the resolution to a Defect Report, this feature is disabled by default in all language versions, and can be enabled explicitly with the flag -frelaxed-template-template-args in Clang 4. The change to the standard lacks a corresponding change for template partial ordering, resulting in ambiguity errors for reasonable and previously-valid code. This issue is expected to be rectified soon.



激活此功能后会破坏哪种构造?为什么会破坏代码以及如何破坏代码?

最佳答案

您可以具有如下代码:

template<template<typename> typename>
struct Foo {};

template<typename, typename = void>
struct Bar {};

Foo<Bar> unused;

如果没有缺陷解决方案,则unused会格式错误,因为foo采用的模板只有一个模板参数,而不是两个。如果您依赖于此(对于SFINAE而言):
template<template<typename> typename>
void foo();

template<template<typename, typename> typename>
void foo();

template<typename, typename = void>
struct Bar {};

int main() {
    foo<Bar>(); // ambiguous after resolution!
}

然后, call 将失败!问题在于部分排序没有相应的更改,因此两个候选函数都具有相同的生存能力,并且调用不明确。

关于c++ - P0522R0的中断代码如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62847485/

相关文章:

c++ - 堆栈数组变量损坏

c++ - Win32 应用程序在最小化窗口动画时挂起

c++ - 如何在 X Windows 上将进程窗口置于前台? (C++)

c - stdio 错误检测 : ferror versus fclose

c++ - Windows 7(32 位)上带有 libstdc++-6.dll 的 clang++ 3.2

c++ - 为什么我不能 memmove std::string?

c++ - 为什么要编译 class::class::class::static Class Member()(在 C++ 中)?

c++ - C++ 中允许使用什么 "conversion"的模板模板参数?

c++ - 当使用__block时,clang BlocksRuntime在可执行文件中嵌入 'obsolete compiler'警告

c++ - Variadic 模板错误 -- MSVS2013 编译,clang-3.5 不编译