Skip to content

Commit f592ba9

Browse files
committed
Use std::uncaught_exceptions whenever it is supported
Don't rely on __cpp_lib_uncaught_exceptions being defined, this doesn't work for at least MSVS which, nevertheless, does provide this function since MSVS 2015 version and, worse, gives warning about using deprecated std::uncaught_exception() since MSVS 2017. Check __cplusplus for the value indicating C++17 support and fall back on checking MSVS version directly as it doesn't define __cplusplus correctly neither by default (this requires using the special /Zc:__cplusplus option which is only available since 2017.7 and not in the previous versions).
1 parent 12ead5c commit f592ba9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

hdr/sqlite_modern_cpp/utility/uncaught_exceptions.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@
44
#include <exception>
55
#include <iostream>
66

7+
// Consider that std::uncaught_exceptions is available if explicitly indicated
8+
// by the standard library, if compiler advertises full C++17 support or, as a
9+
// special case, for MSVS 2015+ (which doesn't define __cplusplus correctly by
10+
// default as of 2017.7 version and couldn't do it at all until it).
11+
#ifndef MODERN_SQLITE_UNCAUGHT_EXCEPTIONS_SUPPORT
12+
#ifdef __cpp_lib_uncaught_exceptions
13+
#define MODERN_SQLITE_UNCAUGHT_EXCEPTIONS_SUPPORT
14+
#elif __cplusplus >= 201703L
15+
#define MODERN_SQLITE_UNCAUGHT_EXCEPTIONS_SUPPORT
16+
#elif defined(_MSC_VER) && _MSC_VER >= 1900
17+
#define MODERN_SQLITE_UNCAUGHT_EXCEPTIONS_SUPPORT
18+
#endif
19+
#endif
20+
721
namespace sqlite {
822
namespace utility {
9-
#ifdef __cpp_lib_uncaught_exceptions
23+
#ifdef MODERN_SQLITE_UNCAUGHT_EXCEPTIONS_SUPPORT
1024
class UncaughtExceptionDetector {
1125
public:
1226
operator bool() {

tests/exception_dont_execute_nested.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct A {
2121
};
2222

2323
TEST_CASE("Nested prepered statements wont execute", "[nested_prepared_statements]") {
24-
#ifdef __cpp_lib_uncaught_exceptions
24+
#ifdef MODERN_SQLITE_UNCAUGHT_EXCEPTIONS_SUPPORT
2525
try {
2626
A a;
2727
throw 1;

0 commit comments

Comments
 (0)