PDA

View Full Version : A patch to fix some compiler warnings in qwt



alex_sh
16th November 2010, 09:55
Hello,

I'm posting this here because my emails to qwt-interest don't seem to be getting through (they're not shown in sourceforge archives).

We're building a partial version of Qwt6 (SVN version) as part of our project build (generating qwt shared library).

Here are the gcc flags we're using:
-Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wpointer-arith -Wsign-compare -Wsign-promo -Wundef -Wwrite-strings

I'm attaching a patch (against current SVN) that fixes some of the warnings. The majority of them is about casting away const qualifiers. There's also one about QwtPlotZoomer::move() hiding QwtPlotPicker::move() and one uncertain choice of overload in QDebug operator<<( QDebug debug, const QwtScaleMap &map ).

Note that while this is the majority of warnings we get, it's not all of them. I may be able to do another full sweep later (and send another patch).

The patch: 5463

Cheers and thanks for the great library,
Alexander

P.S. These are the warnings I fixed:


qwt_dyngrid_layout.cpp: In member function ‘int QwtDynGridLayout::maxRowWidth(int) const’:
qwt_dyngrid_layout.cpp:288:32: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
qwt_dyngrid_layout.cpp: In member function ‘virtual int QwtDynGridLayout::maxItemWidth() const’:
qwt_dyngrid_layout.cpp:314:32: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
qwt_dyngrid_layout.cpp: In member function ‘QList<QRect> QwtDynGridLayout::layoutItems(const QRect&, uint) const’:
qwt_dyngrid_layout.cpp:359:52: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
qwt_dyngrid_layout.cpp: In member function ‘void QwtDynGridLayout::layoutGrid(uint, QVector<int>&, QVector<int>&) const’:
qwt_dyngrid_layout.cpp:412:32: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
qwt_legend.cpp: In member function ‘const QWidget* QwtLegend::PrivateData::LegendMap::find(const QwtLegendItemManager*) const’:
qwt_legend.cpp:158:57: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
qwt_legend.cpp:161:48: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
qwt_legend.cpp: In member function ‘QWidget* QwtLegend::PrivateData::LegendMap::find(const QwtLegendItemManager*)’:
qwt_legend.cpp:166:57: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
qwt_legend.cpp:169:48: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
qwt_legend.cpp: In member function ‘const QwtLegendItemManager* QwtLegend::PrivateData::LegendMap::find(const QWidget*) const’:
qwt_legend.cpp:175:46: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
qwt_legend.cpp:178:37: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
qwt_legend.cpp: In member function ‘QwtLegendItemManager* QwtLegend::PrivateData::LegendMap::find(const QWidget*)’:
qwt_legend.cpp:184:46: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
qwt_legend.cpp:187:63: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
qwt_legend.cpp:187:69: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
qwt_picker.cpp: In member function ‘virtual void QwtPicker::transition(const QEvent*)’:
qwt_picker.cpp:1046:54: warning: cast from type ‘const QMouseEvent*’ to type ‘QMouseEvent*’ casts away qualifiers
qwt_picker.cpp: In member function ‘virtual QRect QwtPicker::pickRect() const’:
qwt_picker.cpp:1343:30: warning: cast from type ‘const QFrame*’ to type ‘QFrame*’ casts away qualifiers
qwt_plot_canvas.cpp: In member function ‘const QwtPlot* QwtPlotCanvas::plot() const’:
qwt_plot_canvas.cpp:81:29: warning: cast from type ‘const QwtPlot*’ to type ‘QwtPlot*’ casts away qualifiers
qwt_plot_magnifier.cpp: In member function ‘const QwtPlotCanvas* QwtPlotMagnifier::canvas() const’:
qwt_plot_magnifier.cpp:90:36: warning: cast from type ‘const QwtPlotMagnifier* const’ to type ‘QwtPlotMagnifier*’ casts away qualifiers
qwt_plot_magnifier.cpp: In member function ‘const QwtPlot* QwtPlotMagnifier::plot() const’:
qwt_plot_magnifier.cpp:110:36: warning: cast from type ‘const QwtPlotMagnifier* const’ to type ‘QwtPlotMagnifier*’ casts away qualifiers
qwt_plot_panner.cpp: In member function ‘const QwtPlotCanvas* QwtPlotPanner::canvas() const’:
qwt_plot_panner.cpp:97:33: warning: cast from type ‘const QwtPlotPanner* const’ to type ‘QwtPlotPanner*’ casts away qualifiers
qwt_plot_panner.cpp: In member function ‘const QwtPlot* QwtPlotPanner::plot() const’:
qwt_plot_panner.cpp:117:33: warning: cast from type ‘const QwtPlotPanner* const’ to type ‘QwtPlotPanner*’ casts away qualifiers
qwt_plot_picker.cpp: In member function ‘const QwtPlotCanvas* QwtPlotPicker::canvas() const’:
qwt_plot_picker.cpp:116:33: warning: cast from type ‘const QwtPlotPicker* const’ to type ‘QwtPlotPicker*’ casts away qualifiers
qwt_plot_picker.cpp: In member function ‘const QwtPlot* QwtPlotPicker::plot() const’:
qwt_plot_picker.cpp:136:33: warning: cast from type ‘const QwtPlotPicker* const’ to type ‘QwtPlotPicker*’ casts away qualifiers
qwt_plot_renderer.cpp: In member function ‘virtual void QwtPlotRenderer::renderLegendItem(const QwtPlot*, QPainter*, const QWidget*, const QRectF&) const’:
qwt_plot_renderer.cpp:540:50: warning: cast from type ‘const QwtLegendItem*’ to type ‘QwtLegendItem*’ casts away qualifiers
qwt_plot_renderer.cpp: In member function ‘virtual void QwtPlotRenderer::renderScale(const QwtPlot*, QPainter*, int, int, int, int, const QRectF&) const’:
qwt_plot_renderer.cpp:644:65: warning: cast from type ‘const QwtScaleDraw*’ to type ‘QwtScaleDraw*’ casts away qualifiers
qwt_plot_rescaler.cpp: In member function ‘const QwtPlotCanvas* QwtPlotRescaler::canvas() const’:
qwt_plot_rescaler.cpp:282:35: warning: cast from type ‘const QwtPlotRescaler* const’ to type ‘QwtPlotRescaler*’ casts away qualifiers
qwt_plot_rescaler.cpp: In member function ‘const QwtPlot* QwtPlotRescaler::plot() const’:
qwt_plot_rescaler.cpp:302:35: warning: cast from type ‘const QwtPlotRescaler* const’ to type ‘QwtPlotRescaler*’ casts away qualifiers
qwt_plot_rescaler.cpp: In member function ‘virtual void QwtPlotRescaler::updateScales(QwtInterval*) const’:
qwt_plot_rescaler.cpp:578:38: warning: cast from type ‘const QwtPlot*’ to type ‘QwtPlot*’ casts away qualifiers
qwt_plot_scaleitem.cpp: In member function ‘virtual void QwtPlotScaleItem::draw(QPainter*, const QwtScaleMap&, const QwtScaleMap&, const QRectF&) const’:
qwt_plot_scaleitem.cpp:330:59: warning: cast from type ‘const QwtPlotScaleItem* const’ to type ‘QwtPlotScaleItem*’ casts away qualifiers
In file included from qwt_plot_zoomer.cpp:10:0:
qwt_plot_picker.h:104:18: warning: ‘virtual void QwtPlotPicker::move(const QPoint&)’ was hidden
qwt_plot_zoomer.h:70:18: warning: by ‘virtual void QwtPlotZoomer::move(double, double)’
qwt_raster_data.cpp: In member function ‘virtual QwtRasterData::ContourLines QwtRasterData::contourLines(const QRectF&, const QSize&, const QList<double>&, int) const’:
qwt_raster_data.cpp:270:25: warning: cast from type ‘const QwtRasterData* const’ to type ‘QwtRasterData*’ casts away qualifiers
qwt_raster_data.cpp:382:25: warning: cast from type ‘const QwtRasterData* const’ to type ‘QwtRasterData*’ casts away qualifiers
qwt_scale_map.cpp: In function ‘QDebug operator<<(QDebug, const QwtScaleMap&)’:
qwt_scale_map.cpp:287:39: warning: passing ‘QwtScaleTransformation::Type’ chooses ‘int’ over ‘unsigned int’
qwt_scale_map.cpp:287:39: warning: in call to ‘QDebug& QDebug::operator<<(int)’
qwt_text.cpp: In destructor ‘QwtTextEngineDict::~QwtTextEngineDict()â₠¬â„¢:
qwt_text.cpp:67:67: warning: cast from type ‘const QwtTextEngine*’ to type ‘QwtTextEngine*’ casts away qualifiers
qwt_text.cpp: In member function ‘const QwtTextEngine* QwtTextEngineDict::textEngine(const QString&, QwtText::TextFormat) const’:
qwt_text.cpp:84:47: warning: cast from type ‘const QwtTextEngine*’ to type ‘QwtTextEngine*’ casts away qualifiers

Uwe
18th November 2010, 07:17
warnings about C casts ...
Well warnings about that casts are casting - even if the compiler offers to enable such warnings they doesn't make much sense to me. And enabling additional warning levels for compiling 3rd party libraries doesn't seem to be something that a user needs to do.

Anyway, the reason for these warnings is because Qwt still uses C casts instead of C++ casts. This decsision was made because of compiler limitations 10 years ago. This should be pointless nowadays and Qt itself uses C++ casts.

I will replace all C casts.


There's also one about QwtPlotZoomer::move()

This one is indeed worth a warning as the compiler can't identify the right move method from the parameter type, when one of them has been overloaded. I will change this.

uncertain choice of overload in QDebug operator<<( QDebug debug, const QwtScaleMap &map )
When you mean the missing enum to int cast - I will add it.

Uwe

alex_sh
18th November 2010, 08:01
Thanks, I hope the patch is helpful as well, you can see from it that I actually removed some of the casts because they were unnecessary (perhaps they were copy/paste leftovers).