- 
    
Bug
 - 
    Resolution: Done
 - 
    
P2: Important
 - 
    5.9.1
 - 
    None
 - 
    Windows 10 x64
Qt 5.9.1 x64 from Msys2
GCC (G++) 7.2 x64 from Msys2
CMake 3.9.2 x64 from Msys2
Qt Creator 4.4.0 
Steps to reproduce:
1. Open the attached simple project where a class derives from QObject and has Q_OBJECT macro inside its body.
2. Compile it with GCC (G++) with -Wuseless-cast (already in CMakeLists.txt).
Expected result:
Successful compilation with no warnings or errors.
Actual result:
The compiler displays a warning in the MOC generated function
    Foo::qt_metacast(const char *_clname)
in line
    return static_cast<void*>(const_cast< Foo*>(this));
Full warning:
D:\dev\project\test\useless-cast-test\main.cpp:13: In file included from D:/dev/project/test/useless-cast-test/main.cpp:13:0:
D:\dev\project\test\build-useless-cast-test-Qt_5_9_1_MinGW_x64_GCC_7_2-Debug\useless-cast-test_autogen\include\main.moc:-1: In member function 'virtual void* Foo::qt_metacast(const char*)':
D:\dev\project\test\build-useless-cast-test-Qt_5_9_1_MinGW_x64_GCC_7_2-Debug\useless-cast-test_autogen\include\main.moc:79: warning: useless cast to type 'Foo*' [-Wuseless-cast]
 return static_cast<void*>(const_cast< Foo*>(this));
                                                                              ^
The problem is worse when you compile with -Werror to treat every warning as error, because then it's not obvious how to fix this issue.