GCC 8, std::uncaught_exceptions, -std=c++17

Jeffrey Walton noloader@gmail.com
Wed Feb 21 21:05:00 GMT 2018


On Wed, Feb 21, 2018 at 9:22 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 21 February 2018 at 14:15, Jeffrey Walton wrote:
>> Hi Everyone,
>>
>> I'm trying to determine when I can use std::uncaught_exceptions().
>>
>>   $ cat test.cxx
>>   #include <iostream>
>>
>>   #ifndef __has_feature
>>   #  define __has_feature(x) 0
>>   #endif
>>
>>   #if _MSC_VER >= 1900
>>   #  define MY_EXCEPTIONS 1
>>   #elif __has_feature(cxx_exceptions)
>
> __has_feature is a Clang extension, GCC doesn't support it, so this is
> always false.
>
>>   #  define MY_EXCEPTIONS 1
>>   #endif
>>
>>   #ifdef MY_EXCEPTIONS
>>   #  include <exception>
>>   #endif
>>
>>   int main(int argc, char* argv[])
>>   {
>>   #ifdef MY_EXCEPTIONS
>>     std::cout << std::uncaught_exceptions() << std::endl;
>
> You're assuming that if Clang's cxx_exceptions feature is present then
> so is the new C++17 function, which is wrong.
>
> The recommended way to test for exceptions being enabled is to test
> #if __cpp_exceptions
> (that works on Clang and GCC, but not MSVC because they don't support
> WG21 SD-6 feature-test macros).
>
> The recommended way to test for std::uncaught_exceptions is #if
> __cpp_lib_uncaught_exceptions >= 201411
> (that works with libstdc++ but not MSVC or libc++ because they don't
> support WG21 SD-6 feature-test macros for the standard library).
>
> SD-6 can be found at
> https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations

Oh, thanks. I was not aware __has_feature was not standard. Derp...

Jeff



More information about the Gcc-help mailing list