Bug #983
Fix Compiler Warnings when using GCC 4.8.1-4
0%
Description
When trying to build exiv2 on Windows using gcc-4.8.1-4, the compiler throws certain warnings during the build:
$ make [...] libtool: compile: g++ -O2 -Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W -MMD -I. -DEXV_LOCALEDIR=\"/usr/local/share/locale\" -I../xmpsdk/include -c -DEXV_BUILDING_LIB=1 basicio.cpp -DDLL_EXPORT -DPIC -o .libs/basicio.o basicio.cpp: In member function 'DWORD Exiv2::FileIo::Impl::winNumberOfLinks() const': basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::ftCreationTime' [-Wmissing-field-initializers] BY_HANDLE_FILE_INFORMATION fi = {0}; ^ basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::ftLastAccessTime' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::ftLastWriteTime' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::dwVolumeSerialNumber' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::nFileSizeHigh' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::nFileSizeLow' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::nNumberOfLinks' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::nFileIndexHigh' [-Wmissing-field-initializers] basicio.cpp:322:55: warning: missing initializer for member '_BY_HANDLE_FILE_INFORMATION::nFileIndexLow' [-Wmissing-field-initializers] [...] V_BUILDING_LIB=1 pentaxmn.cpp -DDLL_EXPORT -DPIC -o .libs/pentaxmn.o pentaxmn.cpp:668:5: warning: narrowing conversion of '4278190080u' from 'unsigned int' to 'long int' inside { } is ill-formed in C++11 [-Wnarrowing] }; ^ [...] libtool: compile: gcc -O2 -Wall -MMD -I. -DEXV_LOCALEDIR=\"/usr/local/share/locale\" -I../xmpsdk/include -c -DEXV_BUILDING_LIB=1 localtime.c -DDLL_EXPORT -DPIC -o .libs/localtime.o localtime.c: In function 'time2sub': localtime.c:1126:29: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] return (*number < number0) != (delta < 0); ^ localtime.c:1126:29: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] return (*number < number0) != (delta < 0); ^ localtime.c:1126:29: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] return (*number < number0) != (delta < 0); ^ localtime.c:1126:29: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow] return (*number < number0) != (delta < 0); ^ localtime.c:1126:29: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow] return (*number < number0) != (delta < 0); ^ [...] $ gcc -v Using built-in specs. COLLECT_GCC=c:\mingw\bin\gcc.exe COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe Target: mingw32 Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++ ,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld -- with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable- libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/ mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T Thread model: win32 gcc version 4.8.1 (GCC)
Package Name: mingw32-gcc 4.8.1-4
The number of compiler warnings differs with different versions of gcc-4.8.1-x, where x ∈ {1,2,3,4}
Files
History
Updated by Nehal J Wani over 7 years ago
- Subject changed from Fix Compiler Warning when using GCC 4.8.1-4 to Fix Compiler Warnings when using GCC 4.8.1-4
Updated by Robin Mills over 7 years ago
- Category set to build
- Status changed from New to Assigned
- Assignee set to Nehal J Wani
- Target version set to 0.25
Thanks for reporting this, Nehal. i'm going to assign this one for you to fix.
I suggest you update https://cocoatutorials.googlecode.com/svn/exiv2 to the current trunk and submit your changes there. This branch is monitored and built by the exiv2.dyndns.org. It's compiling fine on Cygwin and Ubuntu with 4.8.2. It's not linking and running the tests, however I'll probably fix that on Monday. Curiously, 4.8.2 is not getting those messages. So please take care that when you fix this for 4.8.1x, you don't upset 4.8.2.
If your write access to the trunk isn't setup when your fixes are ready, I'll integrate from cocoa-exiv2 to trunk on your behalf and credit you with the fix.
Updated by Nehal J Wani over 7 years ago
The first compiler warning can be taken care of by replacing
BY_HANDLE_FILE_INFORMATION fi = {0}
with
BY_HANDLE_FILE_INFORMATION fi;
gcc-4.8.1-4 thinks that only the last element is being initialized, which is probably not what we wanted. Anyway, initialization of all the members of the struct _BY_HANDLE_FILE_INFORMATION is taken care of by the function GetFileInformationByHandle
Updated by Nehal J Wani over 7 years ago
The second compiler warning is due to the numeric value of the tag
{ 0xff000000, N_("Video") },
in src/pentaxmn.cpp, line 652
It is a member of the array pentaxDriveMode[] which is of type TagDetails.
struct TagDetails { long val_; //!< Tag value const char* label_; //!< Translation ofthe tag value //! Comparison operator for use with the find template bool operator==(long key) const { return val_ == key; } }; // struct TagDetails
For x86 compilation, gcc-4.8.1-4 throws:
pentaxmn.cpp:668:5: warning: narrowing conversion of '4278190080u' from 'unsigned int' to 'long int' inside { } is ill-formed in C++11 [-Wnarrowing]
The reason is that the compiler interprets 0xff000000 as 4278190080, which doesn't fit in long (4bytes) on a x86 platform.
- Solution 1: Change line 187 of /src/tags_int.hpp
long val_; //!< Tag value
toint64_t val_; //!< Tag value
so that we forcefully increase the size of variable val_ from 4bytes to 8bytes on x86 platform.
- Solution 2: Change the value of from 0xff000000 to something which fits under 32 bits signed integer. I tried changing it to 0x7FFFFFFF which is 2147483647 in decimal.
Both solution 1 and solution 2 work. Which one should should I be applying?
Updated by Robin Mills over 7 years ago
Solution 1 seems better. Have you tried it on a 32 bit build?
Updated by Nehal J Wani over 7 years ago
I have tried both solutions on MinGW+gcc-4.8.1-4
and both seem to be working fine with respect to compilation.
Updated by Nehal J Wani over 7 years ago
MinGW
builds for win32
(So I guess, x86 platform has been tested)
Updated by Nehal J Wani over 7 years ago
The third compiler warning comes from the function increment_overflow
in src/localtime.c
. This seems to be a standard file being used by many open source programs around the world. So, if I change the body of the function with the body of a different version of the same function from localtime.c , then gcc-4.8.1-4
is happy. See for the compiler's happiness.
Updated by Nehal J Wani over 7 years ago
Diff solving these three compiler warnings attached.
Updated by Robin Mills about 7 years ago
Patch submitted: r3303. Thank You, Nehal for your work on this.