What does a function attribute mean?

What does this C ++ 11 syntax mean?

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

The standard C ++ N3797 working draft states

The first declaration of the function indicates the noreturn attribute, if any declaration of this function points to the noreturn attribute. If a function is declared with an attribute noreturnin one translation unit and the same function is declared without noreturn in another translation unit, the program is poorly formed; no diagnostics required.

What is meant by a function attribute?

+4
source share
4 answers

, . "" : , .

, , , . ,

  • (.. )
  • , ( fork)
  • , ..

/ .

,

main() {
    f();
    g();
}

f() noreturn, g(), .

+4

- ++ 11. , - , . , ( noreturn carries_dependency), .

, noreturn : , , , undefined. ( ) , , noreturn. .

+4

[[noreturn]] .

#include <stdexcept>

[[noreturn]] void report_error()
{
    throw std::runtime_error("error");
}

int f(int x)
{
    if (x > 0) {
        return x;
    }
    report_error();
}

int main()
{
    f(1);
}

[[noreturn]], f(): warning: control may reach end of non-void function.

+2

GCC " noreturn , . , , , - . . , .

+1

Source: https://habr.com/ru/post/1539130/


All Articles