-
Notifications
You must be signed in to change notification settings - Fork 543
CXX-3296 fix build if GCC/GNU/Clang/MSVC
macro defined
#1409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ISABLE_IMPL_FOR_GNU`
…ISABLE_IMPL_FOR_GCC`
…_DISABLE_IMPL_FOR_Clang`
…DISABLE_IMPL_FOR_MSVC`
To fix `-Werror=pedantic` warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was adding macro selection suffixes (Clang
, GCC
, GNU
, and MSVC
) to the list of guarded macros considered?
// #pragma push_macro("GCC")
// #pragma undef GCC
#include <bsoncxx/v1/detail/prelude.hpp>
... // Public header code.
// #pragma pop_macro("GCC")
#include <bsoncxx/v1/detail/postlude.hpp>
I do not think we reasonably expect any platforms or third party libraries to define any of these macros (as they are usually prefixed with at least one underscore _
) in such a way that guarding them within our public headers would change library behavior. I would consider support for users building the C++ Driver libraries with such macros defined to be out-of-scope (they should be user-defining such macros in their code, not ours), but that doesn't seem to be the case for the referenced user report (diagnostic points to public header code which should be guarded).
GCC/Clang/MSVC
macro definedGCC/GNU/Clang/MSVC
macro defined
Thank you for the suggestion. That seems to fit the purpose of the macro guards and is a smaller change. Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion; otherwise, LGTM.
src/bsoncxx/test/CMakeLists.txt
Outdated
@@ -139,9 +139,13 @@ if(ENABLE_MACRO_GUARD_TESTS) | |||
BSONCXX_PRIVATE_STRINGIFY_IMPL | |||
BSONCXX_PRIVATE_UNREACHABLE | |||
BSONCXX_PRIVATE_WARNINGS_DISABLE | |||
Clang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest keeping this list alphabetically sorted (+ consistent with the order of pragmas in macro guard headers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* guard Clang/GCC/GNU/MSVC macros
* guard Clang/GCC/GNU/MSVC macros
Summary
Fix build if
GCC/GNU/Clang/MSVC
macros are already defined.Tested with this patch build.
Background
https://www.mongodb.com/community/forums/t/error-compiling-some-c-classes-with-driver-v4-0/321847 reports a build error due to the macro
GCC
being defined. I can reproduce the error by adding#define GCC 1
before including C++ driver headers:This PR changes the
BSONCXX_PRIVATE_WARNINGS_DISABLE*
macros to avoid assumingGCC/Clang/MSVC
are not already defined:This PR assumes the
BSONCXX_PRIVATE_*
macros are OK to rename in a non-major API release. The macros are in a public header, but documented as private (refer: API Versioning).