-
Notifications
You must be signed in to change notification settings - Fork 543
CXX-3072 Reduce Warnings - Code Consistency and Quality Improvements #1178
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
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.
Besides not being sure about your question on write_concern::level::k_acknowledged
LGTM!
@@ -175,6 +175,9 @@ bsoncxx::v_noabi::document::value write_concern::to_document() const { | |||
if (auto t = tag()) { | |||
doc.append(kvp("w", *t)); | |||
} | |||
break; | |||
|
|||
case write_concern::level::k_acknowledged: |
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.
is the write_concern::level::k_acknowledged do-nothing fallthrough in write_concern.cpp correct?
I checked out the API reference and the MongoDB docs, not sure myself.
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.
I expect this case is unreachable. If this else
block is entered, then nodes()
did not return a value. That implies acknowledge_level()
cannot be k_acknowledged
.
I expect this could assert:
case write_concern::level::k_acknowledged:
// Acknowledged write concern is expected to return `nodes()` above.
MONGOCXX_UNREACHABLE;
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.
Given prior default:
behavior, opting to preserve break;
behavior rather than introducing an assertion out of caution given the somewhat indirect relationship between is_acknowledged()
and get_w()
. However, will include a comment documenting the relationship with the returned optional.
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.
The warning reductions are appreciated. LGTM with a possible use of BSONCXX_UNREACHABLE
.
@@ -175,6 +175,9 @@ bsoncxx::v_noabi::document::value write_concern::to_document() const { | |||
if (auto t = tag()) { | |||
doc.append(kvp("w", *t)); | |||
} | |||
break; | |||
|
|||
case write_concern::level::k_acknowledged: |
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.
I expect this case is unreachable. If this else
block is entered, then nodes()
did not return a value. That implies acknowledge_level()
cannot be k_acknowledged
.
I expect this could assert:
case write_concern::level::k_acknowledged:
// Acknowledged write concern is expected to return `nodes()` above.
MONGOCXX_UNREACHABLE;
Summary
Resolves CXX-3072. Verified by this patch.
Similar to mongodb/mongo-c-driver#1543 for the C Driver. Addresses 615 Clang warnings (83 unique warnings) with Clang 19.
scoped_bson_value
A long overdue followup to #955:
This addresses
-Wunused-member-function
warnings inoptions.cpp
due to unused functions with internal linkage (default ctor +value_for_init
).C-Style Casts
A large part of this PR is devoted to addressing
-Wold-style-cast
warnings.Most cases only needed a trivial change from
(T)expr
tostatic_cast<T>(expr)
. Regarding numeric casts, range checks have not been added: those may be audited in the future when an assertion/contract methodology for the C++ Driver is implemented (directly reusing C Driver'sBSON_ASSERT()
does not seem ideal).A notable change is the use of
const_cast
to workaround thevoid*
parameter (lack of const) inbsoncxx::v_noabi::types::bson_value::view
's private member functions. To avoid unnecessarily breaking ABI compatibility, aconst_cast
is used instead of updating the parameter type, accompanied by a comment documenting the context and its validity (the const is recovered in the_init
function + correspondingconvert_from_libbson()
overloads updated with the missingconst
for consistency).Miscellaneous
Other warnings addressed by this PR include:
error_code.cpp
in particular).write_concern::level::k_acknowledged
do-nothing fallthrough inwrite_concer.cpp
correct?#if defined(X)
instead of#if X
whenX
is not guaranteed to be defined.static
->inline
for function definitions in headers used by multiple components (where internal linkage does not seem sufficiently motivated).NULL
->nullptr
even with C APIs (C idioms shouldn't leak into C++ code).0
->nullptr
in pointer comparisons and initialization.Ignored Warnings
The following warnings were observed but deliberately unaddressed/ignored/silenced:
-Wdocumentation
: addressed by CXX-3070 Address -Wdocumentation Clang warnings #1175.-Walign-mismatch
inbsoncxx/v_noabi/bsoncxx/private/stack.hh
: unclear how to resolve this warning.-Wexit-time-destructors
for exception types: deferred to a future API major release.-Wglobal-constructors
+-Wexit-time-destructors
foruri::k_default_uri
: deferred to a future API major release.-Wundefined-func-template
forsoft_declval
: deferred to v1 migration PRs (CXX-2745).-Wweak-vtables
for exception types: deferred to a future API major release.