How to deal with noexcept in Visual Studio

前端 未结 11 1811
一整个雨季
一整个雨季 2021-01-31 07:42

I\'m trying to create a custom exception that derives from std::exception and overrides what(). At first, I wrote it like this:

class U         


        
11条回答
  •  独厮守ぢ
    2021-01-31 08:21

    "noexcept" is only supported since the Visual Studio 2015 (as stated here: https://msdn.microsoft.com/en-us/library/wfa0edys.aspx). I have used following code with Visual Studio 2013 (derived from above examples):

    #if !defined(HAS_NOEXCEPT)
    #if defined(__clang__)
    #if __has_feature(cxx_noexcept)
    #define HAS_NOEXCEPT
    #endif
    #else
    #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
        defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026
    #define HAS_NOEXCEPT
    #endif
    #endif
    
    #ifdef HAS_NOEXCEPT
    #define NOEXCEPT noexcept
    #else
    #define NOEXCEPT
    #endif
    

提交回复
热议问题