<bdo id='1pmdD'></bdo><ul id='1pmdD'></ul>
  • <i id='1pmdD'><tr id='1pmdD'><dt id='1pmdD'><q id='1pmdD'><span id='1pmdD'><b id='1pmdD'><form id='1pmdD'><ins id='1pmdD'></ins><ul id='1pmdD'></ul><sub id='1pmdD'></sub></form><legend id='1pmdD'></legend><bdo id='1pmdD'><pre id='1pmdD'><center id='1pmdD'></center></pre></bdo></b><th id='1pmdD'></th></span></q></dt></tr></i><div id='1pmdD'><tfoot id='1pmdD'></tfoot><dl id='1pmdD'><fieldset id='1pmdD'></fieldset></dl></div>

      <small id='1pmdD'></small><noframes id='1pmdD'>

      <tfoot id='1pmdD'></tfoot>

    1. <legend id='1pmdD'><style id='1pmdD'><dir id='1pmdD'><q id='1pmdD'></q></dir></style></legend>

        回归虚无?

        时间:2023-05-25
          <bdo id='v5iLP'></bdo><ul id='v5iLP'></ul>

              <i id='v5iLP'><tr id='v5iLP'><dt id='v5iLP'><q id='v5iLP'><span id='v5iLP'><b id='v5iLP'><form id='v5iLP'><ins id='v5iLP'></ins><ul id='v5iLP'></ul><sub id='v5iLP'></sub></form><legend id='v5iLP'></legend><bdo id='v5iLP'><pre id='v5iLP'><center id='v5iLP'></center></pre></bdo></b><th id='v5iLP'></th></span></q></dt></tr></i><div id='v5iLP'><tfoot id='v5iLP'></tfoot><dl id='v5iLP'><fieldset id='v5iLP'></fieldset></dl></div>

              <tfoot id='v5iLP'></tfoot>
                <tbody id='v5iLP'></tbody>

                <legend id='v5iLP'><style id='v5iLP'><dir id='v5iLP'><q id='v5iLP'></q></dir></style></legend>
                1. <small id='v5iLP'></small><noframes id='v5iLP'>

                  本文介绍了回归虚无?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我不明白为什么这段代码编译没有错误:

                  I do not understand why this code compiles without error:

                  #include <iostream>
                  
                  template <class T>
                  struct Test
                  {
                      static constexpr T f() {return T();} 
                  };
                  
                  int main()
                  {
                      Test<void> test;
                      test.f(); // Why not an error?
                      return 0;
                  }
                  

                  按照标准是可以的,还是编译器的容忍度?

                  Is it ok according to the standard, or is it a compiler tolerance?

                  推荐答案

                  这看起来有效 草案 C++11 标准,如果我们查看 5.2.3 部分 显式类型转换(功能符号)em> 段落 2 说(强调我的):

                  This looks valid by the draft C++11 standard, if we look at section 5.2.3 Explicit type conversion (functional notation) paragraph 2 says (emphasis mine):

                  表达式 T(),其中 T 是简单类型说明符或非数组完整对象类型的类型名称说明符 或(可能是 cv 限定的)void 类型,创建指定类型,其值是由值初始化产生的(8.5) 类型 T 的对象;void() 没有初始化案例.[...]

                  The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified) void type, creates a prvalue of the specified type, whose value is that produced by value-initializing (8.5) an object of type T; no initialization is done for the void() case.[...]

                  措辞非常相似 pre C++11 也是如此.

                  the wording is pretty similar pre C++11 as well.

                  这在 constexpr 中没问题,尽管 7.1.53 说:

                  This okay in a constexpr even though section 7.1.5 paragraph 3 says:

                  constexpr 函数的定义应满足以下条件约束:

                  The definition of a constexpr function shall satisfy the following constraints:

                  并包括此项目符号:

                  它的返回类型应该是一个文字类型;

                  its return type shall be a literal type;

                  void 不是 C++11 中的 文字,如 3.9 部分 10但是如果我们再看6段,它给出了一个适合这种情况的例外,它说:

                  and void is not a literal in C++11 as per section 3.9 paragraph 10, but if we then look at paragraph 6 it gives an exception that fits this case, it says:

                  如果一个 constexpr 函数的实例化模板特化类模板的模板或成员函数将无法满足constexpr 函数或 constexpr 构造函数的要求,该特化不是 constexpr 函数或 constexpr构造函数.[ 注意:如果函数是成员函数,它将仍然是常量,如下所述.—end note ] 如果没有专业化模板将产生一个 constexpr 函数或 constexpr构造函数,程序格式错误;无需诊断.

                  If the instantiated template specialization of a constexpr function template or member function of a class template would fail to satisfy the requirements for a constexpr function or constexpr constructor, that specialization is not a constexpr function or constexpr constructor. [ Note: If the function is a member function it will still be const as described below. —end note ] If no specialization of the template would yield a constexpr function or constexpr constructor, the program is ill-formed; no diagnostic required.

                  正如凯西在C++14 草案标准 void 是一个文字,这是 3.9 Types10 说:

                  As Casey noted in the C++14 draft standard void is a literal, this is section 3.9 Types paragraph 10 says:

                  一个类型是文字类型,如果它是:

                  A type is a literal type if it is:

                  并包括:

                  ——无效;或

                  这篇关于回归虚无?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  • <bdo id='QYvHU'></bdo><ul id='QYvHU'></ul>

                  • <tfoot id='QYvHU'></tfoot>

                    <small id='QYvHU'></small><noframes id='QYvHU'>

                          <i id='QYvHU'><tr id='QYvHU'><dt id='QYvHU'><q id='QYvHU'><span id='QYvHU'><b id='QYvHU'><form id='QYvHU'><ins id='QYvHU'></ins><ul id='QYvHU'></ul><sub id='QYvHU'></sub></form><legend id='QYvHU'></legend><bdo id='QYvHU'><pre id='QYvHU'><center id='QYvHU'></center></pre></bdo></b><th id='QYvHU'></th></span></q></dt></tr></i><div id='QYvHU'><tfoot id='QYvHU'></tfoot><dl id='QYvHU'><fieldset id='QYvHU'></fieldset></dl></div>
                        1. <legend id='QYvHU'><style id='QYvHU'><dir id='QYvHU'><q id='QYvHU'></q></dir></style></legend>
                            <tbody id='QYvHU'></tbody>