[Mingw-w64-public] [[ noreturn ]]
Hi! When using this the [[ noreturn ]] attribute like this: - void f [[ noreturn ]] (); - I get a warning that reads: warning: 'noreturn' function does return ( http://www.stroustrup.com/C++11FAQ.html#attributes ) What can I do to remove this warning? Thanks -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [[ noreturn ]]
Read the error message and make your function never return. That is all. Paste a testcase next time. -- Best regards, lh_mouse 2015-05-29 - 发件人:"Hotmail \(ArbolOne\)" 发送日期:2015-05-29 10:46 收件人:gcc-help Mailing List,MinGW-64 Mailinglist 抄送: 主题:[Mingw-w64-public] [[ noreturn ]] Hi! When using this the [[ noreturn ]] attribute like this: - void f [[ noreturn ]] (); - I get a warning that reads: warning: 'noreturn' function does return ( http://www.stroustrup.com/C++11FAQ.html#attributes ) What can I do to remove this warning? Thanks -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [[ noreturn ]]
On 05/28/2015 08:46 PM, Hotmail (ArbolOne) wrote: > Hi! > When using this the [[ noreturn ]] attribute like this: - void f [[ > noreturn ]] (); - I get a warning that reads: > warning: 'noreturn' function does return > ( http://www.stroustrup.com/C++11FAQ.html#attributes ) > What can I do to remove this warning? I don't see a warning for the example with GCC 4.8, 4.9, or 5.1. If you do, it might help if you posted the version of GCC you're using and the command line options (for example, like I did below). You could also check Bugzilla for known noreturn bugs (though I couldn't find anything relevant). Martin $ cat t.cpp && g++ -v && g++ -Wall -Wextra -c -pedantic -std=c++11 t.cpp void f [[ noreturn ]] () { throw "error"; } Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/ppc64-redhat-linux/4.8.3/lto-wrapper Target: ppc64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-ppc64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-ppc64-redhat-linux/cloog-install --enable-gnu-indirect-function --enable-secureplt --with-long-double-128 --with-cpu-32=power7 --with-tune-32=power7 --with-cpu-64=power7 --with-tune-64=power7 --build=ppc64-redhat-linux Thread model: posix gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [[ noreturn ]]
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(); } -- I downloaded MinGW-w64 from http://sourceforge.net/projects/mingw-w64/ MinGW-w64 settings: Version 4.9.2 or later Architecture: x86_64 Threads: win32 Exception: seh Please let me know if you need anything else. Thanks a whole bunch for the help, I really appreciated. -Original Message- From: Martin Sebor Sent: Friday, May 29, 2015 12:43 PM To: Hotmail (ArbolOne) ; gcc-help Mailing List ; MinGW-64 Mailinglist Subject: Re: [[ noreturn ]] On 05/28/2015 08:46 PM, Hotmail (ArbolOne) wrote: > Hi! > When using this the [[ noreturn ]] attribute like this: - void f [[ > noreturn ]] (); - I get a warning that reads: > warning: 'noreturn' function does return > ( http://www.stroustrup.com/C++11FAQ.html#attributes ) > What can I do to remove this warning? I don't see a warning for the example with GCC 4.8, 4.9, or 5.1. If you do, it might help if you posted the version of GCC you're using and the command line options (for example, like I did below). You could also check Bugzilla for known noreturn bugs (though I couldn't find anything relevant). Martin $ cat t.cpp && g++ -v && g++ -Wall -Wextra -c -pedantic -std=c++11 t.cpp void f [[ noreturn ]] () { throw "error"; } Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/ppc64-redhat-linux/4.8.3/lto-wrapper Target: ppc64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-ppc64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-ppc64-redhat-linux/cloog-install --enable-gnu-indirect-function --enable-secureplt --with-long-double-128 --with-cpu-32=power7 --with-tune-32=power7 --with-cpu-64=power7 --with-tune-64=power7 --build=ppc64-redhat-linux Thread model: posix gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [[ 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
Re: [Mingw-w64-public] [[ noreturn ]]
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
Re: [Mingw-w64-public] [[ noreturn ]]
Hi, On Fri, May 29, 2015 at 4: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(); > } There's an implicit return at the end of the function. Why are you trying to put the [[ noreturn ]] attribute? > > -- > I downloaded MinGW-w64 from http://sourceforge.net/projects/mingw-w64/ > MinGW-w64 settings: > Version 4.9.2 or later > Architecture: x86_64 > Threads: win32 > Exception: seh > > Please let me know if you need anything else. > > Thanks a whole bunch for the help, I really appreciated. > > > > > > > > > -Original Message- From: Martin Sebor > Sent: Friday, May 29, 2015 12:43 PM > To: Hotmail (ArbolOne) ; gcc-help Mailing List ; MinGW-64 Mailinglist > Subject: Re: [[ noreturn ]] > > > On 05/28/2015 08:46 PM, Hotmail (ArbolOne) wrote: >> >> Hi! >> When using this the [[ noreturn ]] attribute like this: - void f [[ >> noreturn ]] (); - I get a warning that reads: >> warning: 'noreturn' function does return >> ( http://www.stroustrup.com/C++11FAQ.html#attributes ) >> What can I do to remove this warning? > > > I don't see a warning for the example with GCC 4.8, 4.9, or > 5.1. If you do, it might help if you posted the version of > GCC you're using and the command line options (for example, > like I did below). You could also check Bugzilla for known > noreturn bugs (though I couldn't find anything relevant). > > Martin > > $ cat t.cpp && g++ -v && g++ -Wall -Wextra -c -pedantic -std=c++11 t.cpp > void f [[ noreturn ]] () { throw "error"; } > Using built-in specs. > COLLECT_GCC=g++ > COLLECT_LTO_WRAPPER=/usr/libexec/gcc/ppc64-redhat-linux/4.8.3/lto-wrapper > Target: ppc64-redhat-linux > Configured with: ../configure --prefix=/usr --mandir=/usr/share/man > --infodir=/usr/share/info > --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap > --enable-shared --enable-threads=posix --enable-checking=release > --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions > --enable-gnu-unique-object --enable-linker-build-id > --with-linker-hash-style=gnu > --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto > --enable-plugin --enable-initfini-array --disable-libgcj > --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-ppc64-redhat-linux/isl-install > --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-ppc64-redhat-linux/cloog-install > --enable-gnu-indirect-function --enable-secureplt --with-long-double-128 > --with-cpu-32=power7 --with-tune-32=power7 --with-cpu-64=power7 > --with-tune-64=power7 --build=ppc64-redhat-linux > Thread model: posix > gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) > -- -- Andrew Melo -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [[ noreturn ]]
Hi, On Thu, May 28, 2015 at 9:46 PM, Hotmail (ArbolOne) wrote: > Hi! > When using this the [[ noreturn ]] attribute like this: - void f [[ noreturn > ]] (); - I get a warning that reads: > warning: 'noreturn' function does return > ( http://www.stroustrup.com/C++11FAQ.html#attributes ) > What can I do to remove this warning? I suspect that the implicit return at the end of the function triggers the warning. The example you give shows a function that throws unconditionally, meaning the function truly doesn't return. -Andrew > > Thanks -- -- Andrew Melo -- ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public