Skip to content

Commit 8d388dc

Browse files
authored
avoid -Wuseless-cast GCC warnings in Qt mocs (danmar#7751)
example: ``` /home/runner/work/cppcheck/cppcheck/cmake.output.tinyxml2/gui/test/resultstree/__/__/moc_threadhandler.cpp: In static member function ‘static void ThreadHandler::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)’: /home/runner/work/cppcheck/cppcheck/cmake.output.tinyxml2/gui/test/resultstree/__/__/moc_threadhandler.cpp:100:51: error: useless cast to type ‘using _t = void (class ThreadHandler::*)()’ {aka ‘void (class ThreadHandler::*)()’} [-Werror=useless-cast] 100 | if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&ThreadHandler::done)) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
1 parent f8eea15 commit 8d388dc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ CheckOptions:
7575
# caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638
7676
target_compile_options_safe(cppcheck-gui -Wno-ctad-maybe-unsupported)
7777
endif()
78+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
79+
# caused by mocs
80+
target_compile_options_safe(cppcheck-gui -Wno-useless-cast)
7881
endif()
7982
if(QT_VERSION VERSION_GREATER_EQUAL "6.9.2")
8083
# QBrush fails to compile before 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-134038

gui/test/resultstree/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4343
# caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638
4444
target_compile_options_safe(test-resultstree -Wno-ctad-maybe-unsupported)
4545
endif()
46-
# caused by mocks
46+
# caused by mocs
4747
target_compile_options_safe(test-resultstree -Wno-missing-noreturn)
48+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
49+
# caused by mocs
50+
target_compile_options_safe(test-resultstree -Wno-useless-cast)
4851
endif()
4952

5053
if (REGISTER_GUI_TESTS)

0 commit comments

Comments
 (0)