Skip to content
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

Fix some Pervasive Clang Warnings #250

Merged
merged 3 commits into from
Apr 16, 2024

Conversation

pniedzielski
Copy link
Collaborator

When compiling the BlazingMQ on a modern version of Clang on a Mac, we get many more warnings that we do not see on GCC. Often, these warnings are on code in header files, and so they are repeated for every translation unit that includes these headers. This PR fixes three such warnings, cutting down on the number of warnings for each compilation significantly: fixing -Wmismatched-tags, using the proper BDE configuration for Clang, and disabling a warning for intended preprocessor behavior. Please see commit messages for each patch for more details.

The `bmqa::MessageImpl` class is declared in the `bmqa_message` component as a
`struct`, but is forward-declared in `bmqt_subscription` as a `class`.  This is
valid C++ with our desired semantics, but the clang still warns that under the
Microsoft C++ ABI, this may result in linker errors.  Although we do not
support Windows as a target platform, this warning is pernitious: many
components that use `bmqt_subscription` will see this warning; including those
of users!

While it would be easy to turn off this warning, this patch instead fixes the
warning by changing the `class` forward declaration in `bmqt_subscription` to
match the `struct` declaration in `bmqa_message`.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
The supported compiler on modern MacOS systems is clang; the `gcc` command
forwards to `clang` underlyingly, unless a user explicitly installs GCC.
Unfortunately, our build system was assuming GCC as the compiler on MacOS
systems.  For the most part, this had no adverse effects, as the two frontends
attempt to be compatible.  However, there is one warning that GCC supports that
clang does not, which we were inadvertently passing: `-Wlogical-op`, which in
clang is superseded by `-Wlogical-op-parentheses`.

The primary issue here is that the we outsource some of our CMake configuration
to BDE Tools, but we need to manually select which platform to use.  This patch
manually selects `clang` rather than `gcc` in the `bin/build-darwin.sh` script,
which silences the above warning.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
The BDE idiom for using `BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES`
is by using it in the condition of a preprocessor conditional `#if`, as
follows:

    #if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES

When compiling on a platform that supports C++11, this macro is
undefined; the behavior in this situation is well-defined, though, and
the macro is replaced with `0`, rendering the above condition true.

Clang, however, warns in this situation, letting us know that we are
expanding a macro that is undefined to `0`, which we may not want to do.
Because of how commonly we use this idiom in our codebase, this patch
turns off this warning across all files.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
@pniedzielski pniedzielski added bug Something isn't working A-Broker Area: C++ Broker A-Client Area: C++ SDK A-Build Area: Build System labels Apr 15, 2024
@pniedzielski pniedzielski requested a review from kaikulimu April 15, 2024 22:33
@pniedzielski pniedzielski requested a review from a team as a code owner April 15, 2024 22:33
@pniedzielski pniedzielski merged commit 266caea into bloomberg:main Apr 16, 2024
18 checks passed
@pniedzielski pniedzielski deleted the fix-pernitious-warnings branch May 1, 2024 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Broker Area: C++ Broker A-Build Area: Build System A-Client Area: C++ SDK bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants