Skip to content

Commit 33b5099

Browse files
authored
Fix NativeModule templates to work with clang (#15917)
* Fix NativeModule templates to work with clang * Change files
1 parent 861da78 commit 33b5099

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix NativeModule templates to work with clang",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative.Cxx/ModuleRegistration.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@
1717
// The macros below are internal implementation details for macro defined in nativeModules.h
1818
//
1919

20+
// ADL-based fallback: returns false for any type not tagged by the macros below.
21+
// Using ADL instead of explicit template specialization allows the macros to be
22+
// used inside a namespace (explicit specializations of a global template must
23+
// occur at global scope, which the macros cannot guarantee).
2024
template <typename T>
21-
struct IsReactTurboModule;
25+
constexpr bool ReactIsReactTurboModuleImpl(T *) noexcept {
26+
return false;
27+
}
2228

23-
// Default to false if no specific override
2429
template <typename T>
25-
struct IsReactTurboModule : std::false_type {};
30+
struct IsReactTurboModule : std::bool_constant<ReactIsReactTurboModuleImpl(static_cast<T *>(nullptr))> {};
2631

2732
#define INTERNAL_REACT_MODULE_REGISTRATION_AND_PROVIDER( \
2833
moduleStruct, moduleName, eventEmitterName, isReactTurboModule) \
2934
struct moduleStruct; \
3035
\
31-
template <> \
32-
struct IsReactTurboModule<moduleStruct> : std::isReactTurboModule##_type {}; \
36+
constexpr bool ReactIsReactTurboModuleImpl(moduleStruct *) noexcept { return isReactTurboModule; } \
3337
\
3438
template <class TDummy> \
3539
struct moduleStruct##_ModuleRegistration final : winrt::Microsoft::ReactNative::ModuleRegistration { \
@@ -70,8 +74,7 @@ struct IsReactTurboModule : std::false_type {};
7074
moduleStruct, moduleName, eventEmitterName, isReactTurboModule) \
7175
struct moduleStruct; \
7276
\
73-
template <> \
74-
struct IsReactTurboModule<moduleStruct> : std::isReactTurboModule##_type {}; \
77+
constexpr bool ReactIsReactTurboModuleImpl(moduleStruct *) noexcept { return isReactTurboModule; } \
7578
\
7679
template <class TRegistry> \
7780
constexpr void GetReactModuleInfo(moduleStruct *, TRegistry &registry) noexcept { \

vnext/Microsoft.ReactNative.Cxx/NativeModules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ struct ModuleEventFieldInfo<TFunc<void(TArgs...)> TModule::*> {
918918
return [module = static_cast<ModuleType *>(module), field](IReactContext const &) noexcept {
919919
// Default emitter will do nothing
920920
// This will be replaced with a method that will call the jsi EventEmitter when JS requests the emitter
921-
module->*field = [](TArgs... args) noexcept {};
921+
module->*field = [](TArgs... /*args*/) noexcept {};
922922
};
923923
} else {
924924
return [module = static_cast<ModuleType *>(module), field, eventName, eventEmitterName](

0 commit comments

Comments
 (0)