Skip to content

Commit

Permalink
Fix compile error for non-void-returning inplace_functions
Browse files Browse the repository at this point in the history
The error occurs when testing for or calling an unassigned function.
  • Loading branch information
ssilverman committed Sep 2, 2023
1 parent 6d091ca commit 33ed570
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions 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
Expand Down Expand Up @@ -31,13 +26,21 @@
* DEALINGS IN THE SOFTWARE.
*/

#pragma once

#include <type_traits>
#include <utility>
#include <functional>
#include <cstddef>

// 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 {
Expand Down
15 changes: 9 additions & 6 deletions 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
Expand Down Expand Up @@ -31,13 +26,21 @@
* DEALINGS IN THE SOFTWARE.
*/

#pragma once

#include <type_traits>
#include <utility>
#include <functional>
#include <cstddef>

// 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 {
Expand Down

0 comments on commit 33ed570

Please sign in to comment.