Is noreturn part of the signature of a function? Can be detected?

  • A+

[dcl.attr.noreturn] can be used to mark that a function doesn't return.

[[ noreturn ]] void f() {     throw "error"; } 

Is [[noreturn]] part to the identity/signature of a function? can one detect that a function is noreturn at the time of compilation?

For example,


In case it is not, should I adopt a convention an define a tag struct?

struct noreturn_{noreturn_()=delete;}; ... [[noreturn]] noreturn_ f(){throw "error";} 


If it were part of the type, a properly type checking compiler would not accept e.g., something like:

[[noreturn]] int f(void); int (*fp)(void) = f; 

The above compiles without error. [[noreturn]] is not part of the type. (Incidentally, neither is _Noreturn in C11, where it is placed syntactically into the same category as inline).

As for detecting it, I didn't find any mechanism for it in the C++11 standard draft. A convention such as the one you proposed could allow you to detect it, but you'd be limited to functions that follow such a convention.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: