Fix NativeModule templates to work with clang#15917
Merged
acoates-ms merged 2 commits intomicrosoft:mainfrom Apr 2, 2026
Merged
Fix NativeModule templates to work with clang#15917acoates-ms merged 2 commits intomicrosoft:mainfrom
acoates-ms merged 2 commits intomicrosoft:mainfrom
Conversation
vmoroz
approved these changes
Apr 2, 2026
acoates-ms
added a commit
to acoates-ms/react-native-windows
that referenced
this pull request
Apr 2, 2026
* Fix NativeModule templates to work with clang * Change files
acoates-ms
added a commit
that referenced
this pull request
Apr 2, 2026
* Implement onClick (#15889) * Implement onClick * Change files * Add onAuxClick event * Update snapshots and fix lint error * Fix NativeModule templates to work with clang (#15917) * Fix NativeModule templates to work with clang * Change files * update change files * lint * lint * Remove homeUIA tests * fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Attemping to use the MS.RN.Cxx nativemodule templates in clang results in a build error:
error: class template specialization of 'IsReactTurboModule' must occur at global scope [clang-diagnostic-error]Root cause: IsReactTurboModule was a global-scope template, and the macros tried to create an explicit specialization (template <> struct IsReactTurboModule) wherever they were expanded. C++ requires that specializations occur at the same namespace as the primary template — so if the macro was used inside namespace Foo, the specialization was at ::Foo instead of ::, triggering the error.
Fix ([ModuleRegistration.h:20-87]:
Replaced IsReactTurboModule's primary template with an ADL-based detection scheme. A global template constexpr bool ReactIsReactTurboModuleImpl(T*) provides the false default.
Each macro now injects a non-template constexpr bool ReactIsReactTurboModuleImpl(moduleStruct*) into the current scope (which may be any namespace).
When IsReactTurboModuleFoo::MyModule is instantiated, ReactIsReactTurboModuleImpl(static_castFoo::MyModule*(nullptr)) is evaluated. ADL looks in namespace Foo and finds the non-template overload injected by the macro there — non-template functions are preferred over templates in overload resolution, so it always wins over the fallback.
Microsoft Reviewers: Open in CodeFlow