Bug 725079 - Can not build Qt code with mingw32 gcc that uses dynamic_cast
Summary: Can not build Qt code with mingw32 gcc that uses dynamic_cast
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: mingw32-qt
Version: 15
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Thomas Sailer
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-07-22 18:55 UTC by Mark
Modified: 2011-07-23 09:19 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-07-23 07:29:50 UTC
Type: Bug


Attachments (Terms of Use)
Test case to demonstrate dynamic_cast (663 bytes, application/x-gzip)
2011-07-23 02:42 UTC, Mark
no flags Details

Description Mark 2011-07-22 18:55:54 UTC
Description of problem:
Can not build Qt code with dynamic_cast without getting an error, complains about RTTI being disabled.

Version-Release number of selected component (if applicable):
4.7.1-5.fc15

How reproducible:
use dynamic_cast in code in a Qt project.

Steps to Reproduce:
1.use dynamic_cast in Qt project
2.mingw32-qmake
3.make
  
Actual results:
/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qglobal.h:2388:15: error: 'dynamic_cast_will_always_fail_because_rtti_is_disabled' is not a member of ...


Expected results:
Successful compile

Additional info:
Works successfully on mingw-cross-env.nongnu.org setup.

Comment 1 Thomas Sailer 2011-07-22 19:56:25 UTC
There's nothing within mingw32-qt that defines QT_NO_DYNAMIC_CAST - so it's either a problem within your project or the bug is assigned to the wrong package.

We really need a small simple testcase for this.

Comment 2 Kalev Lember 2011-07-22 20:52:49 UTC
I looked into the bug a bit and QT_NO_DYNAMIC_CAST is apparently coming from qmake.

Reproducer:

[kalev@beagle tmp]$ mkdir /tmp/qmake-test
[kalev@beagle tmp]$ cd /tmp/qmake-test
[kalev@beagle qmake-test]$ cat > test.pro << EOF
> TEMPLATE      = app
> SOURCES       = test.cpp
> EOF
[kalev@beagle qmake-test]$ touch test.cpp
[kalev@beagle qmake-test]$ mingw32-qmake-qt4 
[kalev@beagle qmake-test]$ make
make -f Makefile.Release
make[1]: Entering directory `/tmp/qmake-test'
i686-pc-mingw32-g++ -c -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 --param=ssp-buffer-size=4 -mms-bitfields -O2 -fexceptions -mthreads -Wall -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NO_DYNAMIC_CAST -I'/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore' -I'/usr/i686-pc-mingw32/sys-root/mingw/include/QtGui' -I'/usr/i686-pc-mingw32/sys-root/mingw/include' -I'/usr/i686-pc-mingw32/sys-root/mingw/include/ActiveQt' -I'release' -I'/usr/lib64/qt4/mkspecs/win32-g++-cross' -o release/test.o test.cpp

... and there's the -DQT_NO_DYNAMIC_CAST along with -fno-rtti.

As much as I can tell, qmake somehow includes /usr/lib64/qt4/mkspecs/features/win32/default_pre.prf and that in turn has CONFIG = rtti_off.

The tricky part is that .../win32/default_pre.prf is part of the native qmake install. I wonder if win32/default_pre.prf produced by the mingw32 crossbuild is any different, and what other differences might be in qmake configurations.

Comment 3 Thomas Sailer 2011-07-22 21:12:43 UTC
add CONFIG+=rtti to test.pro

See:
file:///usr/share/doc/qt4/html/qmake-variable-reference.html#config

Comment 4 Mark 2011-07-23 02:42:16 UTC
Created attachment 514807 [details]
Test case to demonstrate dynamic_cast

mingw32-qmake-qt4 
make

i686-pc-mingw32-g++ -c -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 --param=ssp-buffer-size=4 -mms-bitfields -O2 -fexceptions -mthreads -Wall -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NO_DYNAMIC_CAST -I'/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore' -I'/usr/i686-pc-mingw32/sys-root/mingw/include' -I'/usr/i686-pc-mingw32/sys-root/mingw/include/ActiveQt' -I'release' -I'/usr/lib/qt4/mkspecs/win32-g++-cross' -o release/main.o main.cpp
main.cpp: In function 'int main(int, char**)':
main.cpp:36:11: warning: unused variable 'c'
main.cpp:39:11: warning: unused variable 'd'
In file included from /usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qalgorithms.h:45:0,
                 from /usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qdebug.h:45,
                 from /usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/QDebug:1,
                 from main.cpp:8:
/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qglobal.h: In function 'T qt_dynamic_cast_check(X, T*) [with T = bar*, X = foo*]':
main.cpp:36:34:   instantiated from here
/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qglobal.h:2388:15: error: 'dynamic_cast_will_always_fail_because_rtti_is_disabled' is not a member of 'bar*'
/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qglobal.h: In function 'T qt_dynamic_cast_check(X, T*) [with T = baz*, X = foo*]':
main.cpp:39:34:   instantiated from here
/usr/i686-pc-mingw32/sys-root/mingw/include/QtCore/qglobal.h:2388:15: error: 'dynamic_cast_will_always_fail_because_rtti_is_disabled' is not a member of 'baz*'
make[1]: *** [release/main.o] Error 1
make[1]: Leaving directory `/home/mark/test725079'
make: *** [release] Error 2

Comment 5 Mark 2011-07-23 02:45:15 UTC
Thomas Sailer wrote "add CONFIG+=rtti to test.pro"

This works.. Thankyou!

But should it work differently to every other Qt install?

Comment 6 Thomas Sailer 2011-07-23 07:29:50 UTC
Our behaviour seems to be consistent with the downloads from Nokia:
http://developer.qt.nokia.com/forums/viewthread/4359
http://developer.qt.nokia.com/forums/viewthread/2802

It's debatable whether the default of rtti off (and only on windows, apparently) makes sense in this day and age. But you'd have to convince Nokia to change this. Some people claim that rtti on windows is problematic, but I don't know why. And qt has its own rtti system using qobject_cast.

I'm closing this now.

Comment 7 Mark 2011-07-23 09:19:16 UTC
I have absolutely no problem with this, as it doesn't require a Qt rebuild.

At least this is here closed in case anyone else comes across it..


Note You need to log in before you can comment on or make changes to this bug.