Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-1453

Compilation fails on GCC 6 due to -Wignored-attributes



    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.2.0-rc0
    • Component/s: Testing
    • Labels:
    • Backwards Compatibility:
      Fully Compatible


      Locally, when using the cmake line used for Travis:

      cmake -DCMAKE_BUILD_TYPE=$CONFIG -DCMAKE_C_FLAGS="-Wall -Wextra -Wno-attributes -Werror -Wno-error=missing-field-initializers" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wno-attributes -Werror -Wno-error=missing-field-initializers" ..

      I get the following compile error:

      [ 18%] Building CXX object src/mongocxx/CMakeFiles/mongocxx_mocked.dir/bulk_write.cpp.o
      In file included from /home/derick/dev/derickr-mongo-cxx-driver/src/mongocxx/exception/private/mongoc_error.hh:19:0,
                       from /home/derick/dev/derickr-mongo-cxx-driver/src/mongocxx/bulk_write.cpp:22:
      /home/derick/dev/derickr-mongo-cxx-driver/src/mongocxx/private/libmongoc.hh:47:75: error: ignoring attributes on template argument ‘uint32_t (*)(mongoc_bulk_operation_t*, bson_t*, bson_error_t*) {aka unsigned int (*)(_mongoc_bulk_operation_t*, _bson_t*, _bson_error_t*)}’ [-Werror=ignored-attributes]
           extern MONGOCXX_API mongocxx::test_util::mock<decltype(&mongoc_##name)>& name;
      /home/derick/dev/derickr-mongo-cxx-driver/src/mongocxx/private/libmongoc_symbols.hh:16:1: note: in expansion of macro ‘MONGOCXX_LIBMONGOC_SYMBOL’
      /home/derick/dev/derickr-mongo-cxx-driver/src/mongocxx/private/libmongoc.hh:47:75: error: ignoring attributes on template argument ‘void (*)(mongoc_bulk_operation_t*, const bson_t*) {aka void (*)(_mongoc_bulk_operation_t*, const _bson_t*)}’ [-Werror=ignored-attributes]
           extern MONGOCXX_API mongocxx::test_util::mock<decltype(&mongoc_##name)>& name;
      /home/derick/dev/derickr-mongo-cxx-driver/src/mongocxx/private/libmongoc_symbols.hh:18:1: note: in expansion of macro ‘MONGOCXX_LIBMONGOC_SYMBOL’

      In GCC 6, the default flag "-Wignored-attributes" now also shows this warning for template functions apparently.

      Sam Rossi, writes the following about this:

      In order to mock the C++ driver, we're adding hooks into the C driver functions
      Which is being done in the last ifdef stanza in src/mongocxx/private/libmongoc.hh

      On lines 46-7, we define a macro that we can use to reexport the mongoc functions we want to mock

      One of the things we're doing with the reexport is adding the MONGOCXX_API qualifier, which I think we use to make sure stuff is exported properly on Windows

      the attribute isn't on the libmongoc function; we're adding it as part of the reexport
      But apparently starting in GCC6, you can't add attributes to template functions: https://gcc.gnu.org/ml/gcc-patches/2011-06/msg01557.html

      " we don't want to retain attributes on template type arguments, since they aren't part of mangling, so you could get a class template instantiation that is the same type regardless of the alignment of the argument, but the effective argument varies depending on which alignment was first used to instantiate it."
      I don't think that's the exact patch that changes it (since it was in 2011), but I assume it's the same idea

      Since we aren't actually exporting the mongoc functions to users, I'm not even entirely sure why we're adding MONGOCXX_API to the mocked functions in the first place

      Presumably because we need to import them in the tests (which don't have access to private mongocxx functionality as they use it as if it were a separate library)

      So as long as the tests aren't getting errors finding the functions, I think it's fine that the attribute is being lost

      I think it would only cause issues if we supported GCC on Windows, since then we couldn't import our mocked functions in our tests

      But I don't think that's going to happen any time soon, if at all

      In fact, I think we might have even had users reporting issues building our tests with MinGW, so that's probably related

      So as long as MSVC doesn't also start ignoring template attributes, I think we're fine


          Issue Links



              acm Andrew Morrow
              derick Derick Rethans
              0 Vote for this issue
              2 Start watching this issue