From 33ed570ac445d379530c3e55de240508cd4d71fe Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Fri, 1 Sep 2023 19:05:31 -0700 Subject: [PATCH] Fix compile error for non-void-returning inplace_functions The error occurs when testing for or calling an unassigned function. --- teensy3/inplace_function.h | 15 +++++++++------ teensy4/inplace_function.h | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) 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 {