From 8e172b2bc183d0e7430defd7669429699d5b24f7 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 | 11 +++++++---- teensy4/inplace_function.h | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/teensy3/inplace_function.h b/teensy3/inplace_function.h index 0d716d1a..2728a6bb 100644 --- a/teensy3/inplace_function.h +++ b/teensy3/inplace_function.h @@ -1,9 +1,6 @@ #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 @@ -36,8 +33,14 @@ #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..2728a6bb 100644 --- a/teensy4/inplace_function.h +++ b/teensy4/inplace_function.h @@ -1,9 +1,6 @@ #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 @@ -36,8 +33,14 @@ #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 {