This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: [[ noreturn ]]
- From: Martin Sebor <msebor at redhat dot com>
- To: "Hotmail (ArbolOne)" <ArbolOne at hotmail dot ca>, gcc-help Mailing List <gcc-help at gcc dot gnu dot org>, MinGW-64 Mailinglist <mingw-w64-public at lists dot sourceforge dot net>
- Date: Fri, 29 May 2015 15:21:09 -0600
- Subject: Re: [[ noreturn ]]
- Authentication-results: sourceware.org; auth=none
- References: <SNT150-DS8E262EAC98F643CECCCE2BAC90 at phx dot gbl> <55689727 dot 4040502 at redhat dot com> <SNT150-DS816CA9E1DF6BE556CC271BAC90 at phx dot gbl>
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