P0522R0的中断代码如何? [英] How is P0522R0 breaking code?

查看:67
本文介绍了P0522R0的中断代码如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Today I was reading the C++17 support page of clang. I've notice something odd. The feature Matching template template parameters to compatible arguments (P0522R0) is marked as partial, because it must be activate through a switch. Their note says:

尽管是缺陷报告的解决方案,但是此功能在所有语言版本中均默认禁用,并且可以在Clang 4中通过标志-frelaxed-template-template-args明确启用.模板部分排序的相应更改,导致合理且先前有效的代码产生歧义错误.该问题有望很快得到解决.

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.

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

What kind of constructs breaks when this feature is activated? Why can it break code and how?

推荐答案

您可以使用如下代码:

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

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

Foo<Bar> unused;

没有缺陷解决方案,unused会格式错误,因为foo采用的模板只有一个模板参数,而不是两个.如果您依赖于此(也许对于SFINAE):

Without the defect resolution, unused would be ill-formed, because foo takes a template with only one template parameter, and not two. If you relied on this (maybe for 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!
}

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

Then the call would fail! The problem is that there was no corresponding change to partial ordering, and so both candidate functions have the same viability, and the call is ambiguous.

这篇关于P0522R0的中断代码如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆