Skip to content

C++ TurboModule codegen names each method's invoker with a reserved identifier (__<method>) #59843

Description

@YevheniiKotyrlo

Description

The C++ spec header the codegen writes for a C++ TurboModule declares each method's static invoker as __<methodName> and registers it under that name in methodMap_. An identifier that starts with a double underscore is reserved to the implementation ([lex.name]/3, https://eel.is/c++draft/lex.name#3), so a library that compiles its own sources with clang's -Wreserved-identifier cannot include its own generated <Module>JSI.h under the -Werror React Native's build flags carry.

The names come from packages/react-native-codegen/src/generators/modules/GenerateModuleH.js on main (f480836):

  • line 622: static jsi::Value __${prop.name}(jsi::Runtime &rt, TurboModule &turboModule, …)
  • line 187: methodMap_["${methodName}"] = MethodMetadata {.argCount = ${paramCount}, .invoker = __${methodName}};

Expected: the generated header declares and registers each invoker under a name outside the reserved set, for example invoke_${prop.name}, with the methodMap_ key, the arity and the call into the module unchanged, so a header that compiles today still compiles.

Steps to reproduce

  1. Clone the reproducer below. ReproducerApp/specs/NativeSample.ts is a TurboModule spec with one method, add(left: number, right: number): number.
  2. Run its repro.sh in a node:24 container with clang:
    docker run --rm -v "$PWD:/repro:ro" node:24 bash -c \
      'apt-get update -qq && apt-get install -y -qq clang libboost-dev libdouble-conversion-dev libgoogle-glog-dev > /dev/null && bash /repro/repro.sh'
    It installs react-native@nightly, generates the spec with @react-native/codegen's combine-js-to-schema-cli.js and react-native/scripts/generate-specs-cli.js --platform ios --libraryType modules, and compiles the generated SampleJSI.h with clang++ -std=c++20 -fsyntax-only -Werror -Wreserved-identifier, reading ReactCommon and the folly, fmt and fast_float releases React Native pins as system headers.
  3. Expected: the header compiles. Actual: clang refuses the generated invoker:
    ./out/SampleJSI.h:29:21: error: identifier '__add' is reserved because it starts with '__' [-Werror,-Wreserved-identifier]
    SUMMARY: react-native 0.90.0-nightly-20261107-3aed1720f's codegen names the module's invokers with reserved identifiers
    
    bash /repro/repro.sh 0.88.1 shows the same on the latest stable.

React Native Version

0.88.1

Affected Platforms

Build - Linux

Output of npx @react-native-community/cli info

System:
  OS: Linux 6.18 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
  CPU: (24) x64 AMD Ryzen 9 9950X3D 16-Core Processor
  Memory: 120.26 GB / 125.63 GB
  Shell:
    version: 5.2.15
    path: /bin/bash
Binaries:
  Node:
    version: 24.22.2
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.22
    path: /usr/local/bin/yarn
  npm:
    version: 11.19.1
    path: /usr/local/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native:
    installed: 0.90.0-nightly-20261107-3aed1720f
    wanted: ^0.90.0-nightly-20261107-3aed1720f
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

== generate the module's C++ spec
generated out/SampleJSI.h
25:    methodMap_["add"] = MethodMetadata {.argCount = 2, .invoker = __add};
29:  static jsi::Value __add(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
== compile the spec with -Werror -Wreserved-identifier
./out/SampleJSI.h:29:21: error: identifier '__add' is reserved because it starts with '__' [-Werror,-Wreserved-identifier]
1 error generated.
SUMMARY: react-native 0.90.0-nightly-20261107-3aed1720f's codegen names the module's invokers with reserved identifiers

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-codegen-reserved-invoker-names

Screenshots and Videos

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions