From e0e4269e289ef84433d8c10fee721a7983c180ad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 28 Sep 2016 20:01:35 +0200 Subject: tst_QAbstractSlider: fix strict-aliasing warnings GCC warned: tst_qabstractslider.cpp:858:89: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] Qt::Orientation orientation = *reinterpret_cast(&sliderOrientation); ^ tst_qabstractslider.cpp:867:72: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] orientation = *reinterpret_cast(&wheelOrientation); ^ The solution, of course, would be to use a static_cast here, but why go via int in the first place? Qt::Orientation can perfectly well be used in QFETCH, as proven by tst_qmainwindow, among other things. Change-Id: I97916a50405e16d114837bc52580ce6666d74b17 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../qabstractslider/tst_qabstractslider.cpp | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp index 5e461d6a7d..a9fe805e39 100644 --- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp @@ -707,8 +707,8 @@ void tst_QAbstractSlider::wheelEvent_data() QTest::addColumn("wheelScrollLines"); QTest::addColumn("withModifiers"); // use keyboard modifiers while scrolling? (CTRL and SHIFT) QTest::addColumn("deltaMultiple"); // multiples of WHEEL_DELTA - QTest::addColumn("sliderOrientation"); - QTest::addColumn("wheelOrientation"); + QTest::addColumn("sliderOrientation"); + QTest::addColumn("wheelOrientation"); QTest::addColumn("expectedSliderPosition"); QTest::addColumn("distanceFromBottomRight"); // mpointer's distance from bottom-right corner of widget @@ -721,8 +721,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 20 // wheel scroll lines << false // with modifiers << 1 // delta - << int(Qt::Vertical) // orientation of slider - << int(Qt::Vertical) // orientation of wheel + << Qt::Vertical // orientation of slider + << Qt::Vertical // orientation of wheel << 20 // expected position after << QPoint(0,0); @@ -735,8 +735,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 20 // wheel scroll lines << false // with modifiers << 1 // delta - << int(Qt::Vertical) // orientation of slider - << int(Qt::Vertical) // orientation of wheel + << Qt::Vertical // orientation of slider + << Qt::Vertical // orientation of wheel #ifndef Q_OS_MAC << 1 // expected position after #else @@ -753,8 +753,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 20 // wheel scroll lines << false // with modifiers << 1 // delta - << int(Qt::Horizontal) // orientation of slider - << int(Qt::Vertical) // orientation of wheel + << Qt::Horizontal // orientation of slider + << Qt::Vertical // orientation of wheel #ifndef Q_OS_MAC << 1 // expected position after #else @@ -772,8 +772,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 20 // wheel scroll lines << false // with modifiers << 1 // delta - << int(Qt::Horizontal) // orientation of slider - << int(Qt::Vertical) // orientation of wheel + << Qt::Horizontal // orientation of slider + << Qt::Vertical // orientation of wheel #ifndef Q_OS_MAC << 1 // expected position after #else @@ -791,8 +791,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 20 // wheel scroll lines << false // with modifiers << -1 // delta - << int(Qt::Horizontal) // orientation of slider - << int(Qt::Horizontal) // orientation of wheel + << Qt::Horizontal // orientation of slider + << Qt::Horizontal // orientation of wheel << 30 // expected position after << QPoint(1,1); @@ -805,8 +805,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 1 // wheel scroll lines << false // with modifiers << -2 // delta - << int(Qt::Horizontal) // orientation of slider - << int(Qt::Horizontal) // orientation of wheel + << Qt::Horizontal // orientation of slider + << Qt::Horizontal // orientation of wheel << 100 // expected position after << QPoint(0,0); @@ -819,8 +819,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 1 // wheel scroll lines << false // with modifiers << 2 // delta - << int(Qt::Horizontal) // orientation of slider - << int(Qt::Horizontal) // orientation of wheel + << Qt::Horizontal // orientation of slider + << Qt::Horizontal // orientation of wheel << 0 // expected position after << QPoint(0,0); @@ -833,8 +833,8 @@ void tst_QAbstractSlider::wheelEvent_data() << 20 // wheel scroll lines << true // with modifiers << -1 // delta - << int(Qt::Horizontal) // orientation of slider - << int(Qt::Horizontal) // orientation of wheel + << Qt::Horizontal // orientation of slider + << Qt::Horizontal // orientation of wheel << 90 // expected position after << QPoint(0,0); @@ -851,8 +851,8 @@ void tst_QAbstractSlider::wheelEvent() QFETCH(int,wheelScrollLines); QFETCH(bool,withModifiers); QFETCH(int,deltaMultiple); - QFETCH(int,sliderOrientation); - QFETCH(int,wheelOrientation); + QFETCH(Qt::Orientation, sliderOrientation); + QFETCH(Qt::Orientation, wheelOrientation); QFETCH(int,expectedSliderPosition); QFETCH(QPoint,distanceFromBottomRight); @@ -860,18 +860,16 @@ void tst_QAbstractSlider::wheelEvent() QVERIFY(applicationInstance != 0); QApplication::setWheelScrollLines(wheelScrollLines); - Qt::Orientation orientation = *reinterpret_cast(&sliderOrientation); slider->setRange(minimum,maximum); slider->setSliderPosition(initialSliderPosition); slider->setSingleStep(singleStep); slider->setPageStep(pageStep); slider->setInvertedControls(invertedControls); - slider->setOrientation(orientation); + slider->setOrientation(sliderOrientation); Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier; - orientation = *reinterpret_cast(&wheelOrientation); QWheelEvent event(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, - Qt::NoButton, k, orientation); + Qt::NoButton, k, wheelOrientation); QVERIFY(applicationInstance->sendEvent(slider,&event)); #ifdef Q_OS_MAC QEXPECT_FAIL("Normal data page", "QTBUG-23679", Continue); @@ -883,7 +881,7 @@ void tst_QAbstractSlider::wheelEvent() slider->setSliderPosition(initialSliderPosition); k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier; event = QWheelEvent(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, - Qt::NoButton, k, orientation); + Qt::NoButton, k, wheelOrientation); QSignalSpy spy1(slider, SIGNAL(actionTriggered(int))); QSignalSpy spy2(slider, SIGNAL(valueChanged(int))); QVERIFY(applicationInstance->sendEvent(slider,&event)); -- cgit v1.2.3