GCC support for C++ noexcept

Edward Diener eldlistmailingz@tropicsoft.com
Mon Jul 27 04:18:00 GMT 2015


On 7/26/2015 10:03 PM, Jeffrey Walton wrote:
> On Sun, Jul 26, 2015 at 9:55 PM, Jeff Epler <jepler@unpythonic.net> wrote:
>> Noexcept is a C++11 feature, so it has to be enabled by -std=c++11 or
>> -std=gnu++11 (or, on some older gcc verions, -std=c++0x/gnu++0x)
>>
>> $ cat noex.cc
>> void fn() noexcept(false);
>> $ g++ -c noex.cc
>> noex.cc:1:11: error: expected initializer before ‘noexcept’
>>   void fn() noexcept(false);
>>              ^
>> $ g++ -std=c++11 -c noex.cc
>> $
>
> Right.
>
> But these are sources that compile under both C++03 and C++11. If I
> enable the macro for C++11, then I break C++03 because 03 won't know
> what to do with 'noexcept(false)'.
>
> Not defining __cpluplus makes things very difficult....
>

Try

#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
// C++11 is in effect
#endif




More information about the Gcc-help mailing list