From abaa41eaeeee77f4663a8223998fe1a582b80be7 Mon Sep 17 00:00:00 2001 From: Zetok Zalbavar Date: Sat, 24 Sep 2016 12:25:09 +0100 Subject: [PATCH] docs(CONTRIBUTING): add a guideline to not use dynamic casts/RTTI And enforce it during compilation. --- CONTRIBUTING.md | 14 ++++++++++++++ qtox.pro | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d28f24d33..9bf44565e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -310,6 +310,20 @@ QObject notToMentionThatWeUseCamelCase; E.g. https://github.com/qTox/qTox/blob/master/src/misc/flowlayout.cpp + +## Dynamic casts / RTTI + +qTox is compiled without support for RTTI, as such PRs making use of +`dynamic_cast()` will fail to compile and may be rejected on this basis. For +manipulating Qt-based objects, use `qobject_cast()` instead. + +Compiling qTox without RTTI support gives up to 5-6% size reductions on +compiled binary files. The usage of `dynamic_cast()` can also be completely +mitigated when dealing with Qt objects through use of `qobject_cast()` which +behaves very much like C++'s `dynamic_cast()` but without the RTTI overhead. + +Enforced with `-fno-rtti`. + ## Documentaion If you added a new function, also add a doxygen comment before the diff --git a/qtox.pro b/qtox.pro index f8e7c119d..6bd73bd8f 100644 --- a/qtox.pro +++ b/qtox.pro @@ -40,7 +40,7 @@ FORMS += \ CONFIG += c++11 CONFIG += link_pkgconfig -QMAKE_CXXFLAGS += -fno-exceptions +QMAKE_CXXFLAGS += -fno-exceptions -fno-rtti QMAKE_RESOURCE_FLAGS += -compress 9 -threshold 0 # Rules for creating/updating {ts|qm}-files