[CDRIVER-3576] Compiler warnings on mingw-w64 Created: 17/Mar/20  Updated: 28/Oct/23  Resolved: 22/Apr/20

Status: Closed
Project: C Driver
Component/s: mingw
Affects Version/s: 1.16.2
Fix Version/s: 1.17.0-beta2, 1.17.0

Type: Bug Priority: Major - P3
Reporter: Jeroen Ooms Assignee: Roberto Sanchez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-3632 Fix unresolved pedantic warnings Closed

 Description   

Hi! I maintain the R driver, which is based on mongo-c-driver.

After upgrading to 1.16.2 we see the following compiler warnings when compiling with -pedantic. These need to be addressed to publish the R package.

d:/Compiler/gcc-4.9.3/mingw_32/bin/gcc  -I"D:/RCompile/recent/R/include" -DNDEBUG -I../windows/openssl-1.1.1/include -I. -Icommon -DBSON_COMPILATION -DMONGOC_COMPILATION -DMONGOC_HAVE_SASL_CLIENT_DONE -D__USE_MINGW_ANSI_STDIO    -I"d:/Compiler/gcc-4.9.3/local330/include"  -Wno-deprecated-declarations   -pedantic -O2 -Wall  -std=gnu99 -mtune=core2 -c mongoc/mongoc-util.c -o mongoc/mongoc-util.o
mongoc/mongoc-util.c: In function '_mongoc_rand_simple':
mongoc/mongoc-util.c:53:7: warning: spurious trailing '%' in format [-Wformat=]
       MONGOC_ERROR ("rand_s failed: %");
       ^ 

And 

d:/Compiler/gcc-4.9.3/mingw_32/bin/gcc  -I"D:/RCompile/recent/R/include" -DNDEBUG -I../windows/openssl-1.1.1/include -I. -Icommon -DBSON_COMPILATION -DMONGOC_COMPILATION -DMONGOC_HAVE_SASL_CLIENT_DONE -D__USE_MINGW_ANSI_STDIO    -I"d:/Compiler/gcc-4.9.3/local330/include"  -Wno-deprecated-declarations   -pedantic -O2 -Wall  -std=gnu99 -mtune=core2 -c mongoc/mongoc-topology.c -o mongoc/mongoc-topology.o
In file included from mongoc/mongoc-thread-private.h:24:0,
                 from mongoc/mongoc-topology-private.h:26,
                 from mongoc/mongoc-topology.c:25:
mongoc/mongoc-topology.c: In function '_mongoc_topology_start_background_scanner':
common/common-thread-private.h:58:38: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
    (!(*(_t) = CreateThread (NULL, 0, (void *) _f, _d, 0, NULL)))
                                      ^
mongoc/mongoc-topology.c:1352:8: note: in expansion of macro 'bson_thread_create'
    r = bson_thread_create (
        ^
common/common-thread-private.h:58:38: warning: ISO C forbids passing argument 3 of 'CreateThread' between function pointer and 'void *' [-Wpedantic]
    (!(*(_t) = CreateThread (NULL, 0, (void *) _f, _d, 0, NULL)))
                                      ^
mongoc/mongoc-topology.c:1352:8: note: in expansion of macro 'bson_thread_create'
    r = bson_thread_create (
        ^
In file included from D:/Compiler/gcc-4.9.3/mingw_32/i686-w64-mingw32/include/winbase.h:29:0,
                 from D:/Compiler/gcc-4.9.3/mingw_32/i686-w64-mingw32/include/windows.h:70,
                 from D:/Compiler/gcc-4.9.3/mingw_32/i686-w64-mingw32/include/winsock2.h:23,
                 from ./bson/bson-compat.h:48,
                 from ./bson/bson.h:23,
                 from mongoc/mongoc-handshake.h:23,
                 from mongoc/mongoc-topology.c:19:
D:/Compiler/gcc-4.9.3/mingw_32/i686-w64-mingw32/include/processthreadsapi.h:84:28: note: expected 'LPTHREAD_START_ROUTINE' but argument is of type 'void *'
   WINBASEAPI HANDLE WINAPI CreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
                            ^
 

and

d:/Compiler/gcc-4.9.3/mingw_32/bin/gcc  -I"D:/RCompile/recent/R/include" -DNDEBUG -I../windows/openssl-1.1.1/include -I. -Icommon -DBSON_COMPILATION -DMONGOC_COMPILATION -DMONGOC_HAVE_SASL_CLIENT_DONE -D__USE_MINGW_ANSI_STDIO    -I"d:/Compiler/gcc-4.9.3/local330/include"  -Wno-deprecated-declarations   -pedantic -O2 -Wall  -std=gnu99 -mtune=core2 -c mongoc/mongoc-openssl.c -o mongoc/mongoc-openssl.o
mongoc/mongoc-openssl.c: In function '_mongoc_openssl_import_cert_store':
mongoc/mongoc-openssl.c:133:7: warning: format '%X' expects argument of type 'unsigned int', but argument 4 has type 'DWORD' [-Wformat=]
       MONGOC_ERROR ("Can't open CA store: 0x%.8X: '%s'", GetLastError (), msg);
       ^ 

 

A full build log is available here: https://win-builder.r-project.org/incoming_pretest/mongolite_2.2.0_20200317_230736/Windows/00install.out



 Comments   
Comment by Githook User [ 25/May/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3576 fix most GCC pedantic warnings
Branch: r1.17
https://github.com/mongodb/mongo-c-driver/commit/1072ea8c62eea462fcae5ecaf11b6471591fdb1e

Comment by Githook User [ 22/Apr/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3576 fix most GCC pedantic warnings
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/d6984c8331a2bcd2ff0d2850b222d00c20f6a079

Comment by Jeroen Ooms [ 19/Mar/20 ]

I'm not sure. I was testing with -pedantic before, but perhaps the config has changed so that we are hitting new code paths now on Windows. 

For the R driver we hardcode the config files (because the build servers don't use cmake). We only use mingw-w64 gcc compilers + openssl on Windows, to stick close to the unix config.

 - https://github.com/jeroen/mongolite/blob/master/src/mongoc/mongoc-config.h

 - https://github.com/jeroen/mongolite/blob/master/src/bson/bson-config.h

 

 

 

 

 

Comment by Kevin Albertson [ 19/Mar/20 ]

Thanks for the report jeroen@berkeley.edu! This is not new code, though this still seems reasonable to fix. I'm curious why this only showed up now. Do you know if the build not compiling with -pedantic, -std=gnu99, or -Wall before?

We can try to modify/add to our compilation tests to ensure we don't break this again in the future.

Generated at Wed Feb 07 21:18:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.