Overriding a [[noreturn]] virtual function

后端 未结 3 1865
小蘑菇
小蘑菇 2021-01-07 19:26

The [[noreturn]] attribute can be applied to functions that are not meant to return. For example:

[[noreturn]] void will_throw() { throw std::r         


        
3条回答
  •  被撕碎了的回忆
    2021-01-07 20:24

    I have grepped through the standard, and there's no indication that either [[noreturn]] specifically, or attributes more generally, are "inherited" by overriding functions.

    It's hard to prove a negative, and the standard actually doesn't declare this either way but, since A::f() and B::f() are still distinct functions and the only behaviour described is defined in terms of functions, I think you're safe to mark A::f() as [[noreturn]].

    That being said, I can't imagine what useful optimisation the compiler could subsequently perform, given the dynamic dispatch.

提交回复
热议问题