Heim  >  Fragen und Antworten  >  Hauptteil

c++ - 在一个函数前面加[[noreturn]]是什么意思?

怪我咯怪我咯2714 Tage vor937

Antworte allen(1)Ich werde antworten

  • 阿神

    阿神2017-04-17 15:38:26

    这是C++11attribute specifier sequence( http://en.cppreference.com/w/... )

    关于[[noreturn]],官方解释是

    Indicates that the function does not return.
    This attribute applies to function declarations only. The behavior is undefined if the function with this attribute actually returns.

    specifier用来指示函数永不返回
    有助于编译器进行编译优化(如尾递归等),
    也可以用于抑制编译器给出不必要的警告(如int f(); f();,不加[[noreturn]]的话,编译器会警告f()的返回值被忽略)

    但是,若函数的确有返回值,而你却指定[[noreturn]]的话,这就是未定义行为了

    Antwort
    0
  • StornierenAntwort