search

Home  >  Q&A  >  body text

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

怪我咯怪我咯2808 days ago1001

reply all(1)I'll reply

  • 阿神

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

    This is C++11'sattribute specifier sequence( http://en.cppreference.com/w/... )

    About [[noreturn]], the official explanation is

    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.

    The specifier is used for 指示函数永不返回.
    helps the compiler to perform 编译优化 (such as tail recursion, etc.).
    can also be used for 抑制编译器给出不必要的警告 (such as int f(); f();, without adding [[noreturn]], the compiler will warn that the return value of f() is ignored)

    However, if the function does have a return value and you specify [[noreturn]], this is undefined behavior

    reply
    0
  • Cancelreply