Thank you, I did not understand the purpose of the attribute, but now it is 
clear.


-----Original Message----- 
From: Martin Sebor
Sent: Friday, May 29, 2015 5:21 PM
To: Hotmail (ArbolOne) ; gcc-help Mailing List ; MinGW-64 Mailinglist
Subject: 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


------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to