C++1z 中的 §12.3.2 [class.conv.fct]/1 相对于 C++14 发生了重大变化。是否有意义?
§12.3.2 [class.conv.fct]/1 in C++1z changed substantially in relation to C++14. Does it make sense?
§12.3.2 [class.conv.fct]/1 在 C++14 中:
A member function of a class X having no parameters with a name of the
form
conversion-function-id:
operator
conversion-type-id
conversion-type-id:
type-specifier-seq
conversion-declaratoropt
conversion-declarator:
ptr-operator
conversion-declaratoropt
specifies a conversion from X to the type specified by the
conversion-type-id. Such functions are called conversion functions. No return type can be specified. If a conversion function is a member
function, the type of the conversion function (8.3.5) is “function
taking no parameter returning conversion-type-id”. ...
§12.3.2 [class.conv.fct]/1 in C++1z:(相关更改在下面突出显示)
A member function of a class X having no parameters with a name of the
form
conversion-function-id:
operator
conversion-type-id
conversion-type-id:
type-specifier-seq
conversion-declaratoropt
conversion-declarator:
ptr-operator
conversion-declaratoropt
specifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall be neither
a defining-type-specifier nor static. Type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id”. ...
我想不出没有 decl-specifier-seq 或 decl-specifier-seq 的转换函数不包含 定义类型说明符 。据我所知,这意味着 conversion-function-id,其 conversion-type-id 没有类型!
A conversion-type-id 不包含 decl-specifier-seq;它包含一个 type-specifier-seq。
那句话是关于这个 decl-specifier-seq 在转换函数的 declaration/definition:
struct C {
constexpr inline explicit operator int() const { return 0; }
// ^^^^^^^^^^^^^^^^^^^^^^^^^
operator float() const;
// ^ no decl-specifier-seq here
};
由于显而易见的原因,它不能包含 定义类型说明符。
更改的要点是,当 return 类型由 conversion-type-id 确定时,说 "no return type can be specified" 会产生误导。
§12.3.2 [class.conv.fct]/1 在 C++14 中:
A member function of a class X having no parameters with a name of the form
conversion-function-id:
operator conversion-type-id
conversion-type-id:
type-specifier-seq conversion-declaratoropt
conversion-declarator:
ptr-operator conversion-declaratoroptspecifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. No return type can be specified. If a conversion function is a member function, the type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id”. ...
§12.3.2 [class.conv.fct]/1 in C++1z:(相关更改在下面突出显示)
A member function of a class X having no parameters with a name of the form
conversion-function-id:
operator conversion-type-id
conversion-type-id:
type-specifier-seq conversion-declaratoropt
conversion-declarator:
ptr-operator conversion-declaratoroptspecifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall be neither a defining-type-specifier nor static. Type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id”. ...
我想不出没有 decl-specifier-seq 或 decl-specifier-seq 的转换函数不包含 定义类型说明符 。据我所知,这意味着 conversion-function-id,其 conversion-type-id 没有类型!
A conversion-type-id 不包含 decl-specifier-seq;它包含一个 type-specifier-seq。
那句话是关于这个 decl-specifier-seq 在转换函数的 declaration/definition:
struct C {
constexpr inline explicit operator int() const { return 0; }
// ^^^^^^^^^^^^^^^^^^^^^^^^^
operator float() const;
// ^ no decl-specifier-seq here
};
由于显而易见的原因,它不能包含 定义类型说明符。
更改的要点是,当 return 类型由 conversion-type-id 确定时,说 "no return type can be specified" 会产生误导。