c++1z dynamic exception specification error

C++17 removed dynamic exception specifications, as a result of P0003. Before that, they had been deprecated since C++11. They are no longer part of the language, so there isn't really a way to fix it. As long as you need that third party library, until it changes, you're stuck on C++14.


If you're desperate, you could try:

#define throw(...)

but I wouldn't recommend it.


Well i wrote a little workaround.

#if __cplusplus >= 201703L
    /* MySQL override. This needed to be inclided before cppconn/exception.h to define them */
    #include <stdexcept>
    #include <string>
    #include <memory>

    /* Now remove the trow */
    #define throw(...)
    #include <cppconn/exception.h>
    #undef throw /* reset */
#endif

Short explanation: If we're using c++17, throw is not allowed anymore on allocators. If you take a closer look at the header of the library you'll see that there is a macro defined, which contains the definitions for the default allocator within the library. Sadly it can't be overridden because it gets defined there ignoring that's may already be defined. So somehow you have to override the trow anyway.

A basic trick is to override the trow function with a macro. Doing that leads us to the problem that we also override the trow operator for all includes within the library which isn't a good solution (and also doesn't work). As you may know, if you're includeing a header, it will be just included once (mostly, thanks to the header guards). So the trick there is to include the headers, which are included by the library, than override the throw include the header of the target library, which doesn't actually include their header again because we already did.


Ran into the same issue, so I had to change this macro definition in /usr/include/cppconn/exception.h:

#define MEMORY_ALLOC_OPERATORS(Class) \
void* operator new(size_t size) noexcept(false) { return ::operator new(size); }  \
void* operator new(size_t, void*) noexcept; \
void* operator new(size_t, const std::nothrow_t&) noexcept; \
void* operator new[](size_t) noexcept(false); \
void* operator new[](size_t, void*) noexcept; \
void* operator new[](size_t, const std::nothrow_t&) noexcept; \
void* operator new(size_t N, std::allocator<Class>&);