Skip to content

compilation of StackMachine.hpp fails using Clang for Android because <stop_token> is a stub #18

Description

@GrahamAsher

When building the Android version of my CartoType library I got several errors stating that declarations from <stop_token> like std::stop_source did not exist.

The problem was this code in StackMachine.hpp:

// clang does not support stop_source/stop_token yet :-(  but we don't want re-invent the wheel only for clang actually!
#if !defined( __clang__ ) || __has_include( <stop_token> )
# define TEASCRIPT_SUSPEND_REQUEST_POSSIBLE    1
#else
# define TEASCRIPT_SUSPEND_REQUEST_POSSIBLE    0
#endif

#if TEASCRIPT_SUSPEND_REQUEST_POSSIBLE
# include <stop_token>
#endif

__clang__ was defined, making the first part of the condition false, but the <stop_token> header existed, making the second part true, and so TEASCRIPT_SUSPEND_REQUEST_POSSIBLE became 1, causing <stop_token> to be included.

Unfortunately the <stop_token> header in the version of Clang used by the Android NDK version 28 is useless. It is a stub header that does not define std::stop_source, etc. Newer SDK versions, 29 and 30, do not fix the problem unless the flag -fexperimental-library is used, which is usually undesirable.

My current fix, which works correctly, is to change the || to && in the condition, making it:

#if !defined( __clang__ ) && __has_include( <stop_token> )

causing the <stop_token> declarations to be used only if not using clang, and if the header exists.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions