Dealing with compiler warnings

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 21 years 3 months

Dealing with compiler warnings

Post #1by ajtribick » 24.01.2009, 17:07

Compiling the qt4 version using gcc 4.3.2, I get the following warning messages:

Code: Select all

celengine/astro.cpp: In member function ‘const char* astro::Date::toCStr(astro::Date::Format) const’:
celengine/astro.cpp:529: warning: deprecated conversion from string constant to ‘char*’
celengine/astro.cpp:532: warning: deprecated conversion from string constant to ‘char*’
celengine/astro.cpp:535: warning: deprecated conversion from string constant to ‘char*’
celengine/astro.cpp:525: warning: ‘strftime_format’ may be used uninitialized in this function
celengine/astro.cpp: At global scope:
celengine/astro.cpp:109: warning: ‘MonthAbbrList’ defined but not used
In file included from celengine/command.cpp:12:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celengine/globular.cpp:56: warning: ‘bool decreasing(const GBlob&, const GBlob&)’ defined but not used
celengine/image.cpp: In function ‘void PNGReadData(png_struct*, png_byte*, png_size_t)’:
celengine/image.cpp:632: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
celengine/image.cpp: In function ‘Image* LoadPNGImage(const std::string&)’:
celengine/image.cpp:658: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
celengine/marker.cpp: In member function ‘void MarkerRepresentation::render(float) const’:
celengine/marker.cpp:154: warning: enumeration value ‘Crosshair’ not handled in switch
celengine/rendcontext.cpp: In member function ‘virtual void GLSLUnlit_RenderContext::makeCurrent(const Mesh::Material&)’:
celengine/rendcontext.cpp:832: warning: unused variable ‘bumpTex’
celengine/rendcontext.cpp:833: warning: unused variable ‘specTex’
celengine/rendcontext.cpp:834: warning: unused variable ‘emissiveTex’
celengine/render.cpp: In function ‘void renderCrosshair(float, double)’:
celengine/render.cpp:10405: warning: comparison between signed and unsigned integer expressions
/usr/include/c++/4.3/bits/stl_algo.h: In member function ‘void Renderer::renderPlanet(Body&, Point3f, float, float, const Observer&, const Quatf&, float, float)’:
/usr/include/c++/4.3/bits/stl_algo.h:1844: warning: array subscript is above array bounds
celengine/skygrid.cpp: In member function ‘std::string SkyGrid::longitudeLabel(int, int) const’:
celengine/skygrid.cpp:310: warning: deprecated conversion from string constant to ‘char*’
celengine/skygrid.cpp:318: warning: deprecated conversion from string constant to ‘char*’
In file included from celestia/celestiacore.cpp:45:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celestia/celestiacore.cpp: In member function ‘void CelestiaCore::mouseButtonDown(float, float, int)’:
celestia/celestiacore.cpp:684: warning: suggest parentheses around && within ||
celestia/celestiacore.cpp: In member function ‘void CelestiaCore::renderOverlay()’:
celestia/celestiacore.cpp:3662: warning: comparison with string literal results in unspecified behaviour
celestia/celestiacore.cpp: At global scope:
celestia/celestiacore.cpp:3108: warning: ‘void displayAcronym(Overlay&, char*)’ defined but not used
celestia/configfile.cpp: In function ‘CelestiaConfig* ReadCelestiaConfig(std::string, CelestiaConfig*)’:
celestia/configfile.cpp:282: warning: suggest braces around empty body in an ‘else’ statement
In file included from celestia/eclipsefinder.h:18,
                 from celestia/eclipsefinder.cpp:18:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celestia/favorites.cpp: In function ‘void WriteFavoritesList(FavoritesList&, std::ostream&)’:
celestia/favorites.cpp:138: warning: enumeration value ‘PhaseLock_Old’ not handled in switch
celestia/favorites.cpp:138: warning: enumeration value ‘Chase_Old’ not handled in switch
celestia/favorites.cpp:138: warning: enumeration value ‘Unknown’ not handled in switch
celestia/imagecapture.cpp: In function ‘void PNGWriteData(png_struct*, png_byte*, png_size_t)’:
celestia/imagecapture.cpp:113: warning: ignoring return value of ‘size_t fwrite(const void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
celestia/scriptmenu.cpp: In member function ‘virtual bool ScriptScanner::process(const std::string&)’:
celestia/scriptmenu.cpp:53: warning: comparison between signed and unsigned integer expressions
In file included from celestia/url.cpp:23:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/celx.cpp:51:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/celx_frame.cpp:15:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/celx_object.cpp:21:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celestia/celx_object.cpp: In function ‘int object_orbitvisibility(lua_State*)’:
celestia/celx_object.cpp:202: warning: deprecated conversion from string constant to ‘char*’
celestia/celx_object.cpp:204: warning: deprecated conversion from string constant to ‘char*’
celestia/celx_object.cpp:206: warning: deprecated conversion from string constant to ‘char*’
In file included from celestia/celx_observer.cpp:17:
celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtappwin.h:16,
                 from celestia/qt/qtmain.cpp:24:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celestia/qt/qtmain.cpp:29: warning: ‘description’ defined but not used
In file included from celestia/qt/qtappwin.h:16,
                 from celestia/qt/qtappwin.cpp:44:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from ./celestia/url.h:22,
                 from celestia/qt/qtbookmark.cpp:22:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtglwidget.cpp:40:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtappwin.h:16,
                 from celestia/qt/qtpreferencesdialog.cpp:28:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celestia/qt/qtpreferencesdialog.cpp:439: warning: unused parameter ‘m’
celestia/qt/qtpreferencesdialog.cpp:451: warning: unused parameter ‘s’
celestia/qt/qtpreferencesdialog.cpp:463: warning: unused parameter ‘l’
celestia/qt/qtpreferencesdialog.cpp:475: warning: unused parameter ‘pathIdx’
celestia/qt/qtpreferencesdialog.cpp:492: warning: unused parameter ‘dts’
celestia/qt/qtpreferencesdialog.cpp:34: warning: ‘FilterOtherLocations’ defined but not used
In file included from celestia/qt/qtcelestialbrowser.cpp:33:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtdeepskybrowser.cpp:32:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtsolarsystembrowser.cpp:22:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtselectionpopup.cpp:15:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
celestia/qt/qtcolorswatchwidget.cpp:17: warning: unused parameter ‘parent’
In file included from celestia/qt/qttimetoolbar.cpp:16:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtcelestiaactions.cpp:15:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qteventfinder.cpp:30:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtsettimedialog.cpp:23:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtappwin.h:16,
                 from moc_qtappwin.cpp:10:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything
In file included from celestia/qt/qtglwidget.h:19,
                 from moc_qtglwidget.cpp:10:
./celestia/celestiacore.h:38: warning: declaration ‘class astro::Date’ does not declare anything

The attached diff file solves a fair fraction of these: I didn't bother with the globular file because of Fridger's upcoming revision, and I didn't look at the qt-specific code. As for the remainder, I'm not entirely sure how to go about fixing them. The remaining warnings are

Code: Select all

celengine/globular.cpp:56: warning: ‘bool decreasing(const GBlob&, const GBlob&)’ defined but not used
celengine/image.cpp: In function ‘void PNGReadData(png_struct*, png_byte*, png_size_t)’:
celengine/image.cpp:632: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
celengine/image.cpp: In function ‘Image* LoadPNGImage(const std::string&)’:
celengine/image.cpp:658: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
celengine/marker.cpp: In member function ‘void MarkerRepresentation::render(float) const’:
celengine/marker.cpp:154: warning: enumeration value ‘Crosshair’ not handled in switch
/usr/include/c++/4.3/bits/stl_algo.h: In member function ‘void Renderer::renderPlanet(Body&, Point3f, float, float, const Observer&, const Quatf&, float, float)’:
/usr/include/c++/4.3/bits/stl_algo.h:1844: warning: array subscript is above array bounds
celestia/favorites.cpp: In function ‘void WriteFavoritesList(FavoritesList&, std::ostream&)’:
celestia/favorites.cpp:138: warning: enumeration value ‘PhaseLock_Old’ not handled in switch
celestia/favorites.cpp:138: warning: enumeration value ‘Chase_Old’ not handled in switch
celestia/favorites.cpp:138: warning: enumeration value ‘Unknown’ not handled in switch
celestia/imagecapture.cpp: In function ‘void PNGWriteData(png_struct*, png_byte*, png_size_t)’:
celestia/imagecapture.cpp:113: warning: ignoring return value of ‘size_t fwrite(const void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
celestia/qt/qtmain.cpp:29: warning: ‘description’ defined but not used
celestia/qt/qtpreferencesdialog.cpp:439: warning: unused parameter ‘m’
celestia/qt/qtpreferencesdialog.cpp:451: warning: unused parameter ‘s’
celestia/qt/qtpreferencesdialog.cpp:463: warning: unused parameter ‘l’
celestia/qt/qtpreferencesdialog.cpp:475: warning: unused parameter ‘pathIdx’
celestia/qt/qtpreferencesdialog.cpp:492: warning: unused parameter ‘dts’
celestia/qt/qtpreferencesdialog.cpp:34: warning: ‘FilterOtherLocations’ defined but not used
celestia/qt/qtcolorswatchwidget.cpp:17: warning: unused parameter ‘parent’

It would be nice to know whether the patch breaks anything though.
Last edited by ajtribick on 24.01.2009, 23:08, edited 4 times in total.

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 10 months
Location: Seattle, Washington, USA

Re: Dealing with compiler warnings

Post #2by chris » 24.01.2009, 22:10

Andrew,

Thanks for cleaning up these warnings. Your change breaks the MSVC++ build, which still requires MonthAbbrList in astro.cpp. This variable needs to be #ifdef'd out rather than removed completely.

If you modify a file in which the copyright is still assigned to me, feel free to change it to Celestia Development Team.

--Chris

Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 21 years 3 months

Re: Dealing with compiler warnings

Post #3by ajtribick » 24.01.2009, 23:01

Ok, I'm using

Code: Select all

#if !defined(__GNUC__) || defined(_WIN32)
static const char* MonthAbbrList[12] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
#endif


which if I'm doing the logic correctly should match the conditions of the #else block where MonthAbbrList is used. I uploaded a revised diff file into the first post in this thread.

(Somehow missed that usage, probably relying on grep -l too much)

Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 21 years 3 months

Re: Dealing with compiler warnings

Post #4by ajtribick » 26.01.2009, 22:08

Following feedback on the dev list, this patch has now been committed to SVN.

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 8 months
Location: Hamburg, Germany

Re: Dealing with compiler warnings

Post #5by t00fri » 26.01.2009, 23:53

Andrew,

nice to have considerably less warnings. Still under Linux (gcc version 4.2.1) I keep getting quite a few. By typing make >log, only the remaining warnings are printed into the console. Here is what I still get:

Code: Select all

globular.cpp:56: warning: ‘bool decreasing(const GBlob&, const GBlob&)’ defined b                          ut not used
marker.cpp: In member function ‘void MarkerRepresentation::render(float) const’:
marker.cpp:154: warning: enumeration value ‘Crosshair’ not handled in switch
nutation.cpp:236:5: warning: "TEST" is not defined
render.cpp:7000:5: warning: "DEBUG_SECONDARY_ILLUMINATION" is not defined
render.cpp:8619:5: warning: "DEBUG_SECONDARY_ILLUMINATION" is not defined
stardb.cpp:1367:5: warning: "PROFILE_OCTREE" is not defined
In file included from kdeapp.cpp:50:
/opt/kde3/include/kedittoolbar.h:271: warning: ‘KEditToolbarWidget’ has a field ‘                          KEditToolbarWidget::m_inactiveList’ whose type uses the anonymous namespace
/opt/kde3/include/kedittoolbar.h:271: warning: ‘KEditToolbarWidget’ has a field ‘                          KEditToolbarWidget::m_activeList’ whose type uses the anonymous namespace
kdeapp.cpp: In member function ‘void KdeApp::initActions()’:
kdeapp.cpp:746: warning: ‘showToolbar’ is deprecated (declared at /opt/kde3/inclu                          de/kstdaction.h:502)
favorites.cpp: In function ‘void WriteFavoritesList(FavoritesList&, std::ostream&                          )’:
favorites.cpp:138: warning: enumeration value ‘PhaseLock_Old’ not handled in swit                          ch
favorites.cpp:138: warning: enumeration value ‘Chase_Old’ not handled in switch
favorites.cpp:138: warning: enumeration value ‘Unknown’ not handled in switch


Forget about the one from globular.cpp. That will go once I commit my code.

Fridger
Image


Return to “Development”