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 8e172b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions 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
Expand Down Expand Up @@ -36,8 +33,14 @@
#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
11 changes: 7 additions & 4 deletions 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
Expand Down Expand Up @@ -36,8 +33,14 @@
#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 8e172b2

Please sign in to comment.