woboq / verdigris

Qt without moc: set of macros to use Qt without needing moc
https://woboq.com/blog/verdigris-qt-without-moc.html
GNU Lesser General Public License v3.0
643 stars 60 forks source link

g++13: building with UBSan fails #101

Open jcelerier opened 1 year ago

jcelerier commented 1 year ago
$ g++ -fsanitize=undefined -c verdigris/tests/basic/tst_basic.cpp -I/usr/include/qt6 -I/usr/include/qt6/QtCore -I verdigris/src

In file included from verdigris/tests/basic/anothertu.h:24,
                 from verdigris/tests/basic/tst_basic.cpp:26:
verdigris/src/wobjectimpl.h: In instantiation of 'static void w_internal::FriendHelper::propertyOperation(T*, QMetaObject::Call, int, void**) [with T = BTestObj; int I = 0]':
verdigris/src/wobjectimpl.h:1258:40:   required from 'static void w_internal::FriendHelper::qt_static_metacall_impl2(QObject*, QMetaObject::Call, int, void**, std::index_sequence<__indices ...>, std::index_sequence<_Ind ...>, std::index_sequence<__indices ...>) [with T = BTestObj; long unsigned int ...MethI = {0, 1, 2, 3, 4, 5, 6}; long unsigned int ...ConsI = {0}; long unsigned int ...PropI = {0, 1, 2, 3, 4, 5}; std::index_sequence<__indices ...> = std::integer_sequence<long unsigned int, 0, 1, 2, 3, 4, 5, 6>; std::index_sequence<_Ind ...> = std::integer_sequence<long unsigned int, 0>; std::index_sequence<__indices ...> = std::integer_sequence<long unsigned int, 0, 1, 2, 3, 4, 5>]'
verdigris/src/wobjectimpl.h:1302:43:   required from 'static void w_internal::FriendHelper::qt_static_metacall_impl(Ts&& ...) [with T = BTestObj; Ts = {QObject*&, QMetaObject::Call&, int&, void**&}]'
verdigris/tests/basic/tst_basic.cpp:137:1:   required from here
verdigris/src/wobjectimpl.h:1183:41: error: '(BTestObj::getValue != 0)' is not a constant expression
 1183 |             if W_IF_CONSTEXPR (p.getter != nullptr) {
      |                                ~~~~~~~~~^~~~~~~~~~
verdigris/src/wobjectimpl.h:1190:41: error: '(BTestObj::setValue != 0)' is not a constant expression
 1190 |             if W_IF_CONSTEXPR (p.setter != nullptr) {
      |                                ~~~~~~~~~^~~~~~~~~~
jcelerier commented 1 year ago

I'm assuming that for some reason with ubsan, g++13 turns function pointers into more complex objects which aren't constant expressions anymore.. will try to add a check to disable the W_IF_CONSTEXPR in ubsan mode.

Does not seem too easy though: https://stackoverflow.com/questions/76853255/how-to-detect-ubsan-presence-with-g