diff --git a/teensy3/inplace_function.h b/teensy3/inplace_function.h index 0d716d1a..fbc99d1d 100644 --- a/teensy3/inplace_function.h +++ b/teensy3/inplace_function.h @@ -1,9 +1,4 @@ -#pragma once - // https://github.com/WG21-SG14/SG14/blob/master/SG14/inplace_function.h -// -// For use with Teensy, allow uninitialized to be no-operation without error -#define SG14_INPLACE_FUNCTION_THROW(x) /* * Boost Software License - Version 1.0 - August 17th, 2003 @@ -31,13 +26,21 @@ * DEALINGS IN THE SOFTWARE. */ +#pragma once + #include #include #include #include +// Teensy doesn't support runtime exceptions, so calling an uninitialized +// inplace_function needs to call a non-returning function. We can't do nothing +// because that would cause a compile error for non-void-returning functions. +// Additionally, we can't return some default value because that's not possible +// for return types that have a non-trivial constructor. +// See 'invoke_ptr' initialization in 'vtable()' constructor. #ifndef SG14_INPLACE_FUNCTION_THROW -#define SG14_INPLACE_FUNCTION_THROW(x) throw (x) +#define SG14_INPLACE_FUNCTION_THROW(x) std::__throw_bad_function_call() #endif namespace stdext { diff --git a/teensy4/inplace_function.h b/teensy4/inplace_function.h index 0d716d1a..fbc99d1d 100644 --- a/teensy4/inplace_function.h +++ b/teensy4/inplace_function.h @@ -1,9 +1,4 @@ -#pragma once - // https://github.com/WG21-SG14/SG14/blob/master/SG14/inplace_function.h -// -// For use with Teensy, allow uninitialized to be no-operation without error -#define SG14_INPLACE_FUNCTION_THROW(x) /* * Boost Software License - Version 1.0 - August 17th, 2003 @@ -31,13 +26,21 @@ * DEALINGS IN THE SOFTWARE. */ +#pragma once + #include #include #include #include +// Teensy doesn't support runtime exceptions, so calling an uninitialized +// inplace_function needs to call a non-returning function. We can't do nothing +// because that would cause a compile error for non-void-returning functions. +// Additionally, we can't return some default value because that's not possible +// for return types that have a non-trivial constructor. +// See 'invoke_ptr' initialization in 'vtable()' constructor. #ifndef SG14_INPLACE_FUNCTION_THROW -#define SG14_INPLACE_FUNCTION_THROW(x) throw (x) +#define SG14_INPLACE_FUNCTION_THROW(x) std::__throw_bad_function_call() #endif namespace stdext {