Ticket #161 (closed defect: wontfix)

Opened 3 years ago

Last modified 18 months ago

Request to add CFLAG -Werror=declaration-after-statement

Reported by: jmckenna Owned by:
Priority: major Milestone:
Component: Development platform Version:
Keywords: Cc: jmckenna@…

Description

The C89 requirement is a wall that is hit by many software projects (PROJ.4, GDAL, MapServer/MapCache?) as many different compilers support different standards.

MapServer/MapCache? recently added the -Werror=declaration-after-statement to avoid compiler errors when variables are not declared at the beginning of the block: https://github.com/mapserver/mapcache/commit/219e54b45e4730b91111a6874e435a8ca8a1aa6d

Even Rouault recently mentioned that PROJ.4 also uses that flag, which is based on the GDAL use of it also: https://github.com/OSGeo/proj.4/blob/master/m4/ax_cflags_warn_all.m4#L35

Here are more ZOO-Project compile errors on Windows:

d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(273) : error C2061: syntax error : identifier 'hasKey'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(273) : error C2059: syntax error : ';'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(273) : error C2059: syntax error : 'type'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(285) : error C2061: syntax error : identifier 'hasElement'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(285) : error C2059: syntax error : ';'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(285) : error C2059: syntax error : 'type'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(297) : error C2061: syntax error : identifier 'contains'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(297) : error C2059: syntax error : ';'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(297) : error C2059: syntax error : 'type'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(316) : error C2061: syntax error : identifier 'addServiceToRegistry'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(316) : error C2059: syntax error : ';'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(316) : error C2059: syntax error : 'type'
d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(328) : warning C4273: '_snprintf' : inconsistent dll linkage
        C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\stdio.h(349) : see previous definition of '_snprintf'
ulinet.c(92) : error C2143: syntax error : missing ';' before 'type'
ulinet.c(93) : error C2275: '_HINTERNET' : illegal use of this type as an expression
        d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\ulinet.h(87) : see declaration of '_HINTERNET'
ulinet.c(93) : error C2065: 'psInternet' : undeclared identifier
ulinet.c(94) : error C2065: 'psInternet' : undeclared identifier
ulinet.c(94) : warning C4047: '!=' : 'int' differs in levels of indirection from 'void *'
ulinet.c(95) : error C2065: 'psInternet' : undeclared identifier
ulinet.c(95) : error C2223: left of '->cookie' must point to struct/union
ulinet.c(96) : error C2065: 'psInternet' : undeclared identifier
ulinet.c(96) : error C2223: left of '->cookie' must point to struct/union
ulinet.c(246) : warning C4013: 'strtok_r' undefined; assuming extern returning int
ulinet.c(246) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
ulinet.c(247) : error C2143: syntax error : missing ';' before 'type'
ulinet.c(248) : error C2143: syntax error : missing ';' before 'type'
ulinet.c(249) : error C2065: 'cnt' : undeclared identifier
ulinet.c(251) : error C2065: 'cnt' : undeclared identifier
ulinet.c(254) : error C2065: 'cnt' : undeclared identifier
ulinet.c(258) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
ulinet.c(259) : error C2065: 'cnt' : undeclared identifier
ulinet.c(281) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
ulinet.c(282) : error C2143: syntax error : missing ';' before 'type'
ulinet.c(283) : error C2065: 'i' : undeclared identifier
ulinet.c(284) : error C2065: 'i' : undeclared identifier
ulinet.c(289) : error C2143: syntax error : missing ';' before 'type'
ulinet.c(290) : error C2065: 'j' : undeclared identifier
ulinet.c(291) : error C2065: 'j' : undeclared identifier
ulinet.c(292) : error C2065: 'j' : undeclared identifier
ulinet.c(292) : error C2065: 'i' : undeclared identifier
ulinet.c(294) : error C2065: 'j' : undeclared identifier
ulinet.c(295) : error C2065: 'j' : undeclared identifier
ulinet.c(298) : error C2275: 'map' : illegal use of this type as an expression
        d:\build\mapserver-buildkit-2012\zoo-project-svn-20170731\zoo-project\zoo-kernel\service.h(191) : see declaration of 'map'
ulinet.c(298) : error C2065: 'tmpMap' : undeclared identifier
ulinet.c(299) : error C2065: 'tmpMap' : undeclared identifier
ulinet.c(299) : warning C4047: '!=' : 'int' differs in levels of indirection from 'void *'
ulinet.c(300) : error C2065: 'i' : undeclared identifier
ulinet.c(300) : error C2065: 'tmpMap' : undeclared identifier
ulinet.c(300) : error C2223: left of '->value' must point to struct/union
ulinet.c(300) : error C2198: 'AddMissingHeaderEntry' : too few arguments for call
ulinet.c(302) : error C2065: 'i' : undeclared identifier
ulinet.c(303) : error C2065: 'i' : undeclared identifier
ulinet.c(305) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
ulinet.c(539) : warning C4018: '<' : signed/unsigned mismatch
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.

Change History

Changed 3 years ago by djay

Ok, I understand this requirement.

What I don't understand here is that, I suppose you have tried using this flag but it did not solve the issue completely. Can we know what are the compilation result after adding this flag ?

I have another question, did you try to build the 1.6.0 release on windows platform ? I ask this question cause it was the last one that has been tested and build on windows platform. So I suppose that in case the 1.6.0 build then we will "only" to have to track changes and check what I can break on the way. The work to have the windows build working was handled by Knut Landmark, in case you see this ticket, I think your help would be much appreciated here.

I hope we can give a try to the 1.6.0 release to be built on windows.

Changed 3 years ago by jmckenna

  • cc jmckenna@… added

I apologize for not explaining more. This ticket is in fact requesting that the CFLAG switch -Werror=declaration-after-statement be added to the ZOO-Project's main configure file (or configure.ac) - therefore that switch cannot be tested on Windows.

As mentioned previously, this switch handles the requirement of some compilers that follow the C89 standard, where all variables must be declared/initialized at the beginning of a code block - directly after an opening brace { Most OSGeo projects handle that requirement by including the -Werror=declaration-after-statement in their configure script, such as:

  • GDAL: configure line#3942 for ac_arg in "-pedantic -Wdeclaration-after-statement % -Wall -Wdeclaration-after-statement" "-pedantic % -Wall"

Once that switch is added, then the next time you or any other developer tries to compile the ZOO-Project from source, on Ubuntu or whatever Unix flavor, there will be many errors thrown, showing these C89 variable problems (you could test this now as you read, on your machine there). Once those are fixed and committed, then the next time a developer tries to add some C code, the C89 rules are verified in their new code, by that -Wdeclaration-after-statement switch.

Please let me know if that explanation helps, for describing the purpose of this ticket.

Regarding the 1.6.0 release and Windows:

The MS4W build environment uses the Microsoft Visual Studio 2012 compiler (because that specific compiler is required for PHP 5.6, and Python 2.x). The initial ZOO-Project windows builds were done on the Visual Studio 2013 compiler in appveyor by Knut Landmark - the 2013 compiler is more forgiving, and these C89 requirements don't exist.

Of course I can use the 1.6.0 release (yes I have tried, and the same C89 errors, where variables are not declared at the beginning of the block, exist).

So in summary: this will be a team effort. Can you try adding that CFLAG switch to configure in your environment? I will also continue to see if I can fix the C89 errors (hopefully once you add that switch and try compiling, you can also help with the errors).

Thanks. -jeff

Changed 3 years ago by djay

Many thanks for this clarification that make me understand more precisely the issue and the way to solve it.

I will add this flag to the configure options and then solve the reported error.

Thanks again for such a pertinent and helping ticket.

Changed 3 years ago by jmckenna

  • cc jmckenna@… removed

Thanks. My plan is to continue on this tomorrow/Monday, so maybe we can work together on this then.

Changed 3 years ago by jmckenna

  • cc jmckenna@… added

odd how the ticket reported "jmckenna@… removed", was a mistake.

Changed 3 years ago by djay

  • cc jmckenna@… removed

I will follow your plan and it will be a pleasure for me to work with you on this.

Changed 18 months ago by jmckenna

  • cc jmckenna@… added
  • status changed from new to closed
  • resolution set to wontfix

most devs now use c++11 friendly compilers (msvc 2015/2017). Closing.

Note: See TracTickets for help on using tickets.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png