Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3701

Calling topology TRACE macro with no formatted args emits compiler warning

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.17.0-beta2, 1.17.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • None

      I observed the following build warning when compiling libmongoc for PHPC:

      In file included from phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology.c:31:0:
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology.c: In function ‘mongoc_topology_rescan_srv’:
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-trace-private.h:39:19: warning: too many arguments for format [-Wformat-extra-args]
                         "TRACE: %s():%d " msg,  \
                         ^
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology.c:640:4: note: in expansion of macro ‘TRACE’
          TRACE ("Polling for SRV records", NULL);
          ^~~~~
      In file included from phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology-description.c:21:0:
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology-description.c: In function ‘mongoc_topology_description_handle_ismaster’:
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-trace-private.h:39:19: warning: too many arguments for format [-Wformat-extra-args]
                         "TRACE: %s():%d " msg,  \
                         ^
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology-description.c:2001:10: note: in expansion of macro ‘TRACE’
                TRACE ("wrong set name", NULL);
                ^~~~~
      

      This appears to have been introduced in 370fc18 for CDRIVER-3625 and pertains to how TRACE is defined in mongoc-trace-private.h as a proxy to mongoc_log. The macro's msg argument is always expected but subsequent arguments are taken with .... Removing the NULL argument resulted in an outright error:

       
      In file included from phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology.c:31:0:
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology.c: In function ‘mongoc_topology_rescan_srv’:
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-trace-private.h:42:30: error: expected expression before ‘)’ token
                         __VA_ARGS__);           \
                                    ^
      phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology.c:640:4: note: in expansion of macro ‘TRACE’
          TRACE ("Polling for SRV records");
          ^~~~~
      

      If we can't fix this directly, perhaps it'd be best to simply suppress any -Wformat-extra-args warnings around the TRACE macro.

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: