更新时间:2023-12-01 18:51:52
该代码有效.
非类型 template-parameter 的 template-argument 应该是类型的转换后的常量表达式([expr.const]).模板参数.
类型为
T
的转换后的常量表达式是一个隐式转换为类型T
的表达式,其中转换后的表达式为常量表达式,隐式转换序列仅包含[...]
A converted constant expression of type
T
is an expression, implicitly converted to typeT
, where the converted expression is a constant expression and the implicit conversion sequence contains only [...]
(在这种情况下,没有隐式转换.)
(There's no implicit conversion in this case.)
一个常量表达式是[...]或一个prvalue核心常量表达式,其值满足以下约束:
A constant expression is [...] or a prvalue core constant expression whose value satisfies the following constraints:
如果[...]或它是非立即函数,则实体是常量表达式的允许结果.
An entity is a permitted result of a constant expression if [...] or if it is a non-immediate function.
(除了 consteval
功能之外,所有功能都不是直接的.
(All functions are non-immediate except for the consteval
ones. [dcl.constexpr])
因此, s
是类型为 S
的有效转换常量表达式.此外,它不受 [temp.arg.nontype]/3的约束(仅适用于对象的指针/引用).
Therefore, s
is a valid converted constant expression of type S
. In addition, it is not subject to [temp.arg.nontype]/3 (which only applies to pointer/reference to objects).
也就是说, s
是有效的模板参数.
That is, s
is a valid template argument.
我不确定错误消息指的是什么
I'm not sure what the error message is referring to
这是胡说八道.
从 invalid_tparm_referent_p .它是从实现类非类型模板参数时处理对象类型指针的代码中提取的( 4be5c72 ).显然,实现者忘记了更新此功能以解决指针指向功能的情况.
The error is emitted from invalid_tparm_referent_p
inside GCC. It was extracted from code for handling pointer to object type when class non-type template paramter was implemented (4be5c72). Apparently, the implementer forgot to update this function to account for the pointer-to-function case.
我将错误报告为 https://gcc.gnu.org/PR97700 .