[CXX-1453] Compilation fails on GCC 6 due to -Wignored-attributes Created: 23/Oct/17  Updated: 28/Oct/23  Resolved: 06/Nov/17

Status: Closed
Project: C++ Driver
Component/s: Testing
Affects Version/s: None
Fix Version/s: 3.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Derick Rethans Assignee: Andrew Morrow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

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’
 MONGOCXX_LIBMONGOC_SYMBOL(bulk_operation_execute)
 ^~~~~~~~~~~~~~~~~~~~~~~~~
/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’
 MONGOCXX_LIBMONGOC_SYMBOL(bulk_operation_insert)
 ^~~~~~~~~~~~~~~~~~~~~~~~~

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



 Comments   
Comment by Githook User [ 06/Nov/17 ]

Author:

{'name': 'Andrew Morrow', 'username': 'acmorrow', 'email': 'acm@mongodb.com'}

Message: CXX-1453 Suppress ignored attributes in test mocks due to GCC bug
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/8fbd4597388f16685ced4ce9f1399829a89906bd

Generated at Wed Feb 07 22:02:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.