[CDRIVER-3632] Fix unresolved pedantic warnings Created: 22/Apr/20  Updated: 28/Oct/23  Resolved: 19/Aug/21

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.20.0

Type: Improvement Priority: Major - P3
Reporter: Roberto Sanchez Assignee: Ezra Chung
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File build.log    
Issue Links:
Problem/Incident
causes CDRIVER-4151 Incorrect Test Registration with Stat... Closed
Related
related to CDRIVER-3576 Compiler warnings on mingw-w64 Closed
related to CDRIVER-3972 bson-oid.h conversion warning Closed

 Description   

C driver commit d6984c8331a2bcd2ff0d2850b222d00c20f6a079 fixed almost all of the GCC pedantic warnings in the code base (c.f., CDRIVER-3576). However, there was one class of warning where GCC complained of converting between function pointers and object pointers. These still need to be resolved.

The following code block exists in several files in the code base:

/*
 * Prevent failing on pedantic GCC warning: "ISO C forbids conversion of
 * function pointer to object pointer type.
 */
#if __GNUC__ > 6
#pragma GCC diagnostic warning "-Wpedantic"
#else
#pragma GCC diagnostic warning "-pedantic"
#endif

These are the files:

  • src/libmongoc/tests/TestSuite.c
  • src/libmongoc/tests/test-mongoc-client-session.c
  • src/libmongoc/tests/test-mongoc-cursor.c
  • src/libmongoc/tests/test-mongoc-long-namespace.c

In order to properly fix this, the above referenced code block needs to be removed from those files and the code built with the options -pedantic -Wall -Werror. Note that -pedantic and -Wall are defaults when maintainer flags are enabled. However, -Werror is not standard.



 Comments   
Comment by Githook User [ 19/Aug/21 ]

Author:

{'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}

Message: CDRIVER-3632 Address pedantic warnings for function pointer conversions (#850)

Conversion between object pointers and function pointers is undefined
behavior, though permitted as a "common extension" by the C standard
(see N1570 J.5.7 "Function pointer casts").

This commit defines a new TestSuite_AddFullWithTestFn macro as a
convenient utility that defines an intermediate TestFuncCtx object
through which a given function pointer is passed via the ctx parameter
without incurring function pointer <-> object pointer conversions.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/bc6b800f5b190e60ec23c81a9928b230e1dc4d06

Comment by Jeremy Mikola [ 16/Jun/21 ]

I believe I just encountered this while working on CDRIVER-3892 and doing a fresh build of the test suite. I'm attaching build.log for review. My changes for CDRIVER-3892 do not seem related (all contained to test-mongoc-crud.c, which produced no errors), so this is essentially all of the errors in the current HEAD commit: https://github.com/mongodb/mongo-c-driver/commit/2597f6d4d229f437b3b2cdce0e941a925f24491d

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