Skip to content

Support building without RTTI - #13

Merged
amaher-ms merged 1 commit into
masterfrom
amaher/no-rtti
Oct 23, 2026
Merged

amaher-ms merged 1 commit into
masterfrom
amaher/no-rtti

Conversation

@amaher-ms

@amaher-ms amaher-ms commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

FakeIt used dynamic_cast and typeid internally, so it didn't compile with -fno-rtti and was unreliable with /GR-.

  • Internal casts use static_cast where the type is fixed at construction, and typed storage or virtual accessors where a virtual base is involved.
  • Type names in messages come from __PRETTY_FUNCTION__/__FUNCSIG__ instead of typeid.
  • Mocks still get fake RTTI when RTTI is enabled, so typeid and dynamic_cast on mocks keep working.
  • Single headers are regenerated from include/.
  • Tests skip the RTTI-specific cases when RTTI is off, and CI runs the suite with -fno-rtti on GCC and Clang.

Test results match master on GCC, Clang, MSVC and clang-cl, and are the same without RTTI apart from the skipped RTTI tests.

Verified with Mojang/Minecraftpe#99080.

FakeIt used dynamic_cast and typeid internally, so it didn't compile with
-fno-rtti and was unreliable with /GR-.

Internal casts now use static_cast where the type is fixed at construction,
and typed storage or virtual accessors where a virtual base is involved.
Type names in messages come from __PRETTY_FUNCTION__ or __FUNCSIG__ instead
of typeid. Mocks still get fake RTTI when RTTI is enabled, so typeid and
dynamic_cast on mocks keep working.

Tests skip the RTTI-specific cases when RTTI is off, and CI runs the suite
with -fno-rtti on GCC and Clang.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7f5234c6-fb97-4ca8-b48c-16a582a690d7
Comment on lines +25 to +35
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Build project
run: |
cd build
make -f clang_makefile all CXXFLAGS=-fno-rtti
- name: Run tests
run: |
cd build
./fakeit_tests.exe
Comment on lines +50 to +60
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Build project
run: |
cd build
make all CXXFLAGS=-fno-rtti
- name: Run tests
run: |
cd build
./fakeit_tests.exe

@tristanschneider tristanschneider left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. I read through and indeed many of the places looked like they were correct downcasts where the dynamic cast was unnecessary extra safety. The RTTICompleteObjectLocator change apparently looks correct based on what AI is telling me about how that slot works for type information in msvc. I'm not thrilled about the precarious locations that need the rtti ifdefs but don't see a preferrable way around it, and anyway this is an area that doesn't need to change often.

@amaher-ms
amaher-ms merged commit 87af50e into master Oct 23, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants