This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [[ noreturn ]]


On 05/29/2015 03:03 PM, Hotmail (ArbolOne) wrote:
This is the actual code where the test takes place:
void ascii_all [[ noreturn ]] () {
    uint32_t ASCII_MAX = 255;
    std::wstring a;

    for (uint32_t i = 0; i <= ASCII_MAX; i++) {
        a = i;
        size_t w1/*, w2*/;
        if ( i < 10 ) w1 = 3;
        else w1 = 2;
        wcout << setw( w1 )
              << a
              << setw( 6 )
              << i;
    }
    wcout << L"\nThis are the ASCII character from 33 to 255" << std::endl;
//    wcin.get();
}

The function above returns to its caller so the attribute on
its declaration is incorrect and the warning is justified.

The purpose of the noreturn attribute is to indicate to the
compiler that the function doesn't return to its caller (e.g.,
because it always throws an exception or calls abort or exit).
This is useful because then the compiler can then better
optimize callers to the function.

The C++ attribute noreturn is essentially equivalent to GCC
attribute noreturn:

http://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-never-return-3111

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]