This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC 8, std::uncaught_exceptions, -std=c++17
- From: Jeffrey Walton <noloader at gmail dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 21 Feb 2018 09:31:33 -0500
- Subject: Re: GCC 8, std::uncaught_exceptions, -std=c++17
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8n-KeeoYRCxFPhpqzVQSRDUEaQn+r03PbpBbq-gb-R9gA@mail.gmail.com> <CAH6eHdSvw_tJ=qCzOArVomJD=rXop+L4_R55==ACUOcgrk9e0g@mail.gmail.com>
- Reply-to: noloader at gmail dot com
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