简体   繁体   English

在模板模板参数的情况下,decltype(auto)可转发的参考非类型模板参数是否可转发

[英]Are reference non-type template parameters deduced by decltype(auto) forwardable in case of template template parameter

Yet another decltype(auto) template template-parameter question. 又一个decltype(auto)模板模板参数问题。 This time minimal code I was able to create to reproduce the error looks like this: 这次我能够创建的最小代码重现错误如下所示:

template <template <decltype(auto)> class TT, decltype(auto) V>
void foo(TT<V>) {
};

template <decltype(auto)>
struct Bar{};

int x;

int main() {
    foo(Bar<(x)>{});
}

This in [clang] results in: 这在[clang]中导致:

prog.cc:11:5: error: no matching function for call to 'foo'
    foo(Bar<(x)>{});
    ^~~
prog.cc:2:6: note: candidate template ignored: substitution failure [with TT = Bar]: non-type template argument is not a constant expression
void foo(TT<V>) {
     ^
1 error generated.

[gcc] accepts the code. [gcc]接受代码。

To my understanding the code is well-formed and clang is buggy in its interpretation, but need the confirmation before submitting a bug to lvvm. 根据我的理解,代码格式正确,并且clang在解释方面存在错误,但在向lvvm提交错误之前需要确认。 Am I right? 我对吗?

According to error clang does not have a problem with deducing template template-parameter which is also standard compliant - [temp.arg.template]/3 (empasis mine): 根据错误clang没有问题推导模板模板参数 ,这也是标准兼容 - [temp.arg.template] / 3 (empasis mine):

A template-argument matches a template template-parameter P when P is at least as specialized as the template-argument A . 当P至少与模板参数A一样专用时,模板参数匹配模板模板参数P. If P contains a parameter pack, then A also matches P if each of A's template parameters matches the corresponding template parameter in the template-parameter-list of P. Two template parameters match if they are of the same kind (type, non-type, template), for non-type template-parameters, their types are equivalent ([temp.over.link]) , and for template template-parameters, each of their corresponding template-parameters matches, recursively. 如果P包含参数包,那么如果每个A的模板参数与P的模板参数列表中的相应模板参数匹配,则A也匹配P. 两个模板参数匹配,如果它们是相同种类(类型,非类型) ,template),对于非类型模板参数,它们的类型是等价的([temp.over.link]) ,对于模板模板参数,它们的每个相应模板参数都是递归匹配的。 When P's template-parameter-list contains a template parameter pack, the template parameter pack will match zero or more template parameters or template parameter packs in the template-parameter-list of A with the same type and form as the template parameter pack in P (ignoring whether those template parameters are template parameter packs) 当P的template-parameter-list包含模板参数包时,模板参数包将匹配A的template-parameter-list中的零个或多个模板参数或模板参数包,其类型和形式与P中的模板参数包相同。 (忽略这些模板参数是否为模板参数包)

Now lets make sure the Bar<(x)>{} should be deduced as reference. 现在让我们确保推导出Bar<(x)>{}作为参考。 This is covered by [dcl.type.auto.deduct]/5 and [dcl.type.simple]/4 . 这由[dcl.type.auto.deduct] / 5[dcl.type.simple] / 4涵盖

Finally lets check if we actually can use the reference to the variable with linkage as a template argument [temp.arg.nontype]/2 : 最后让我们检查一下我们是否真的可以使用带有链接的变量的引用作为模板参数[temp.arg.nontype] / 2

A template-argument for a non-type template-parameter shall be a converted constant expression of the type of the template-parameter. 非类型模板参数的模板参数应该是模板参数类型的转换常量表达式。 For a non-type template-parameter of reference or pointer type, the value of the constant expression shall not refer to (or for a pointer type, shall not be the address of) : 对于引用或指针类型的非类型模板参数,常量表达式的值不应引用(或者对于指针类型,不应该是地址)

  • a subobject, 一个子对象,
  • a temporary object, 一个临时对象,
  • a string literal, 一个字符串文字,
  • the result of a typeid expression, or typeid表达式的结果,或
  • a predefined 预定义的 ­ func__ variable. func__变量。

[ Note: If the template-argument represents a set of overloaded functions (or a pointer or member pointer to such), the matching function is selected from the set ([over.over]). [注意:如果template-argument表示一组重载函数(或指向此类的指针或成员指针),则从集合中选择匹配函数([over.over])。 — end note ] - 结束说明]

The deduced argument fulfils the requirements. 推导出的论证符合要求。 This makes the code well-formed and suggests clang's bug. 这使代码格式良好,并提出了clang的错误。

Filed bug 34690 提起错误34690

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 C++ 非类型模板参数中使用 decltype(auto) - Using decltype(auto) in C++ non-type template parameter 具有引用非类型模板参数的模板是否应该匹配具有自动非类型模板参数的模板模板参数? - Is a template with reference non-type template parameter supposed to match a template template parameter with an auto non-type template parameter? 推导(非类型)模板参数类型的编译器差异 - Compiler variance for the type of deduced (non-type) template parameter 非类型(引用)模板参数和链接 - Non-type (reference) template parameters and linkage c ++ 17中的非类型模板参数可以是decltype(auto)吗? - Can non-type template parameters in c++17 be decltype(auto)? 模板非类型模板化参考参数 - Template non-type templated reference parameter 在模板模板参数的情况下,非类型模板参数的占位符类型是否可互换 - Are placeholders types of non-type template parameters interchangeable in case of template template parameter 具有混合类型参数和非类型可变参数的模板模板参数 - Template template parameter with mixed type and non-type variadic parameters C ++ 17可以推导出具有显式非类型参数的`auto`非类型`模板`参数模式匹配模板吗? - Can C++17's deduced `auto` non-type `template` parameters pattern-match templates with explicit non-type parameters? 非类型模板参数 - Non-type template parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM