From b67b45ab258d9b7ccfdbfe5a361ecd54da58c4f7 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 13:00:01 -0500 Subject: [PATCH 01/16] Avoid redundant recompilation of mongocxx test components --- src/mongocxx/test/CMakeLists.txt | 111 ++++++++++++------------------- 1 file changed, 43 insertions(+), 68 deletions(-) diff --git a/src/mongocxx/test/CMakeLists.txt b/src/mongocxx/test/CMakeLists.txt index 4bf8e8eb12..08543d1584 100644 --- a/src/mongocxx/test/CMakeLists.txt +++ b/src/mongocxx/test/CMakeLists.txt @@ -29,18 +29,19 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(mongocxx_mocked PRIVATE /bigobj) endif() -set(spec_test_common +add_library(client_helpers OBJECT client_helpers.cpp) + +add_library(spec_test_common OBJECT + spec/monitoring.cpp spec/operation.cpp - spec/unified_tests/entity.cpp spec/unified_tests/assert.cpp - spec/monitoring.cpp + spec/unified_tests/entity.cpp spec/util.cpp ) add_executable(test_driver bulk_write.cpp change_streams.cpp - client_helpers.cpp client_session.cpp client_side_encryption.cpp client.cpp @@ -102,75 +103,41 @@ add_executable(test_driver validation_criteria.cpp write_concern.cpp ) +target_link_libraries(test_driver PRIVATE client_helpers) -add_executable(test_logging - logging.cpp -) +add_executable(test_logging logging.cpp) -add_executable(test_instance - instance.cpp -) +add_executable(test_instance instance.cpp) -add_executable(test_crud_specs - spec/crud.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_crud_specs spec/crud.cpp) +target_link_libraries(test_crud_specs PRIVATE spec_test_common client_helpers) -add_executable(test_gridfs_specs - spec/gridfs.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_gridfs_specs spec/gridfs.cpp) +target_link_libraries(test_gridfs_specs PRIVATE spec_test_common client_helpers) -add_executable(test_client_side_encryption_specs - spec/client_side_encryption.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_client_side_encryption_specs spec/client_side_encryption.cpp) +target_link_libraries(test_client_side_encryption_specs PRIVATE spec_test_common client_helpers) -add_executable(test_command_monitoring_specs - spec/command_monitoring.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_command_monitoring_specs spec/command_monitoring.cpp) +target_link_libraries(test_command_monitoring_specs PRIVATE spec_test_common client_helpers) -add_executable(test_transactions_specs - spec/transactions.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_transactions_specs spec/transactions.cpp) +target_link_libraries(test_transactions_specs PRIVATE spec_test_common client_helpers) -add_executable(test_retryable_reads_specs - spec/retryable-reads.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_retryable_reads_specs spec/retryable-reads.cpp) +target_link_libraries(test_retryable_reads_specs PRIVATE spec_test_common client_helpers) -add_executable(test_read_write_concern_specs - spec/read_write_concern.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_read_write_concern_specs spec/read_write_concern.cpp) +target_link_libraries(test_read_write_concern_specs PRIVATE spec_test_common client_helpers) -add_executable(test_mongohouse_specs - spec/mongohouse.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_mongohouse_specs spec/mongohouse.cpp) +target_link_libraries(test_mongohouse_specs PRIVATE spec_test_common client_helpers) -add_executable(test_unified_format_spec - spec/unified_tests/operations.cpp - spec/unified_tests/runner.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_unified_format_spec spec/unified_tests/operations.cpp spec/unified_tests/runner.cpp) +target_link_libraries(test_unified_format_spec PRIVATE spec_test_common client_helpers) -add_executable(test_versioned_api - versioned_api.cpp - ${spec_test_common} - client_helpers.cpp -) +add_executable(test_versioned_api versioned_api.cpp) +target_link_libraries(test_versioned_api PRIVATE spec_test_common client_helpers) # Common target properties for test executables. add_library(mongocxx_test_properties INTERFACE) @@ -192,17 +159,25 @@ add_library(mongocxx::test_properties_with_main ALIAS mongocxx_test_properties_w set_property( TARGET - test_driver - test_logging - test_instance + client_helpers + spec_test_common + APPEND PROPERTY LINK_LIBRARIES + mongocxx::test_properties +) + +set_property( + TARGET test_client_side_encryption_specs + test_command_monitoring_specs test_crud_specs + test_driver test_gridfs_specs - test_command_monitoring_specs - test_transactions_specs - test_retryable_reads_specs - test_read_write_concern_specs + test_instance + test_logging test_mongohouse_specs + test_read_write_concern_specs + test_retryable_reads_specs + test_transactions_specs test_unified_format_spec test_versioned_api APPEND PROPERTY LINK_LIBRARIES From b38e032b53e55eb8c34587671b257c5a5a1b1000 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:42 -0500 Subject: [PATCH 02/16] Address -Wmissing-prototypes warnings --- ...tic_client_side_field_level_encryption.cpp | 4 + .../mongocxx/get_values_from_documents.cpp | 4 + examples/mongocxx/instance_management.cpp | 4 +- .../mongodb.com/aggregation_examples.cpp | 7 +- .../mongodb.com/documentation_examples.cpp | 5 +- .../mongocxx/mongodb.com/index_examples.cpp | 5 +- .../mongodb.com/runcommand_examples.cpp | 5 +- examples/mongocxx/tailable_cursor.cpp | 4 + src/mongocxx/test/client_helpers.cpp | 2 +- src/mongocxx/test/spec/monitoring.cpp | 2 +- src/mongocxx/test/spec/operation.cpp | 2 +- .../test/spec/unified_tests/assert.cpp | 4 +- .../test/spec/unified_tests/operations.cpp | 114 +++++++++--------- src/mongocxx/test/spec/util.cpp | 7 +- 14 files changed, 94 insertions(+), 75 deletions(-) diff --git a/examples/mongocxx/automatic_client_side_field_level_encryption.cpp b/examples/mongocxx/automatic_client_side_field_level_encryption.cpp index abc9991cca..88ff992d69 100644 --- a/examples/mongocxx/automatic_client_side_field_level_encryption.cpp +++ b/examples/mongocxx/automatic_client_side_field_level_encryption.cpp @@ -45,6 +45,8 @@ using bsoncxx::types::bson_value::make_value; using namespace mongocxx; +namespace { + const int kKeyLength = 96; using ns_pair = std::pair; @@ -92,6 +94,8 @@ bsoncxx::document::value doc_from_file(std::string path) { return bsoncxx::from_json(file_contents); } +} // namespace + int main() { instance inst{}; diff --git a/examples/mongocxx/get_values_from_documents.cpp b/examples/mongocxx/get_values_from_documents.cpp index 229b79654f..67c092a918 100644 --- a/examples/mongocxx/get_values_from_documents.cpp +++ b/examples/mongocxx/get_values_from_documents.cpp @@ -25,6 +25,8 @@ using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_array; using bsoncxx::builder::basic::make_document; +namespace { + // Document model, showing array with nested documents: // // { @@ -118,6 +120,8 @@ void iterate_documents(mongocxx::collection& coll) { } } +} // namespace + int main() { // The mongocxx::instance constructor and destructor initialize and shut down the driver, // respectively. Therefore, a mongocxx::instance must be created before using the driver and diff --git a/examples/mongocxx/instance_management.cpp b/examples/mongocxx/instance_management.cpp index 8265494580..dae68ba911 100644 --- a/examples/mongocxx/instance_management.cpp +++ b/examples/mongocxx/instance_management.cpp @@ -67,8 +67,6 @@ class mongo_access { std::unique_ptr _pool = nullptr; }; -} // namespace - // The 'configure' and 'do_work' functions use the same mongocxx::instance and mongocxx::pool // objects by way of the mongo_access singleton. @@ -97,6 +95,8 @@ bool do_work() { return true; } +} // namespace + int main(int argc, char* argv[]) { auto uri = mongocxx::uri{(argc >= 2) ? argv[1] : mongocxx::uri::k_default_uri}; configure(std::move(uri)); diff --git a/examples/mongocxx/mongodb.com/aggregation_examples.cpp b/examples/mongocxx/mongodb.com/aggregation_examples.cpp index 85a9b0baaf..95586a15fa 100644 --- a/examples/mongocxx/mongodb.com/aggregation_examples.cpp +++ b/examples/mongocxx/mongodb.com/aggregation_examples.cpp @@ -26,11 +26,10 @@ #include #include -// NOTE: Any time this file is modified, a DOCS ticket should be opened to sync the changes with the -// corresponding page on mongodb.com/docs. See CXX-1514, CXX-1249, and DRIVERS-356 for more info. - using namespace mongocxx; +namespace { + void aggregation_examples(const mongocxx::database& db) { { // Start Aggregation Example 1 @@ -143,6 +142,8 @@ void aggregation_examples(const mongocxx::database& db) { } } +} // namespace + int main() { // The mongocxx::instance constructor and destructor initialize and shut down the driver, // respectively. Therefore, a mongocxx::instance must be created before using the driver and diff --git a/examples/mongocxx/mongodb.com/documentation_examples.cpp b/examples/mongocxx/mongodb.com/documentation_examples.cpp index 46af1571ca..8effb86d44 100644 --- a/examples/mongocxx/mongodb.com/documentation_examples.cpp +++ b/examples/mongocxx/mongodb.com/documentation_examples.cpp @@ -33,8 +33,7 @@ #include #include -// NOTE: Any time this file is modified, a DOCS ticket should be opened to sync the changes with the -// corresponding page on mongodb.com/docs. See CXX-1249 and DRIVERS-356 for more info. +namespace { template void check_field(const T& document, @@ -1699,6 +1698,8 @@ static void queryable_encryption_api(mongocxx::client& client) { // End Queryable Encryption Example } +} // namespace + int main() { // The mongocxx::instance constructor and destructor initialize and shut down the driver, // respectively. Therefore, a mongocxx::instance must be created before using the driver and diff --git a/examples/mongocxx/mongodb.com/index_examples.cpp b/examples/mongocxx/mongodb.com/index_examples.cpp index eea69ff83d..1b63f512d5 100644 --- a/examples/mongocxx/mongodb.com/index_examples.cpp +++ b/examples/mongocxx/mongodb.com/index_examples.cpp @@ -17,8 +17,7 @@ #include #include -// NOTE: Any time this file is modified, a DOCS ticket should be opened to sync the changes with the -// corresponding page on mongodb.com/docs. See CXX-1514, CXX-1249, and DRIVERS-356 for more info. +namespace { void index_examples(const mongocxx::database& db) { { @@ -39,6 +38,8 @@ void index_examples(const mongocxx::database& db) { } } +} // namespace + int main() { // The mongocxx::instance constructor and destructor initialize and shut down the driver, // respectively. Therefore, a mongocxx::instance must be created before using the driver and diff --git a/examples/mongocxx/mongodb.com/runcommand_examples.cpp b/examples/mongocxx/mongodb.com/runcommand_examples.cpp index c8c931de6b..ca282852d1 100644 --- a/examples/mongocxx/mongodb.com/runcommand_examples.cpp +++ b/examples/mongocxx/mongodb.com/runcommand_examples.cpp @@ -19,8 +19,7 @@ #include #include -// NOTE: Any time this file is modified, a DOCS ticket should be opened to sync the changes with the -// corresponding page on mongodb.com/docs. See CXX-1514, CXX-1249, and DRIVERS-356 for more info. +namespace { void runcommand_examples(mongocxx::database& db) { { @@ -35,6 +34,8 @@ void runcommand_examples(mongocxx::database& db) { } } +} // namespace + int main() { // The mongocxx::instance constructor and destructor initialize and shut down the driver, // respectively. Therefore, a mongocxx::instance must be created before using the driver and diff --git a/examples/mongocxx/tailable_cursor.cpp b/examples/mongocxx/tailable_cursor.cpp index f44fd607ab..9818f953c4 100644 --- a/examples/mongocxx/tailable_cursor.cpp +++ b/examples/mongocxx/tailable_cursor.cpp @@ -29,6 +29,8 @@ using bsoncxx::builder::basic::document; using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; +namespace { + // // Document number counter for sample inserted documents. This just // makes the tailed document more obviously in sequence. @@ -68,6 +70,8 @@ void insert_docs(mongocxx::collection* coll) { } } +} // namespace + int main() { // The mongocxx::instance constructor and destructor initialize and shut down the driver, // respectively. Therefore, a mongocxx::instance must be created before using the driver and diff --git a/src/mongocxx/test/client_helpers.cpp b/src/mongocxx/test/client_helpers.cpp index 42369ac3ba..d745408f25 100644 --- a/src/mongocxx/test/client_helpers.cpp +++ b/src/mongocxx/test/client_helpers.cpp @@ -323,7 +323,7 @@ bool is_numeric(types::bson_value::view value) { value.type() == type::k_double; } -stdx::optional is_type_operator(types::bson_value::view value) { +static stdx::optional is_type_operator(types::bson_value::view value) { if (value.type() == type::k_document && value.get_document().value["$$type"]) { auto t = value.get_document().value["$$type"].get_string().value; if (t.compare("binData") == 0) { diff --git a/src/mongocxx/test/spec/monitoring.cpp b/src/mongocxx/test/spec/monitoring.cpp index e2d0370a28..c00663e4b9 100644 --- a/src/mongocxx/test/spec/monitoring.cpp +++ b/src/mongocxx/test/spec/monitoring.cpp @@ -32,7 +32,7 @@ namespace spec { using namespace mongocxx; using bsoncxx::to_json; -void remove_ignored_command_monitoring_events(apm_checker::event_vector& events, +static void remove_ignored_command_monitoring_events(apm_checker::event_vector& events, const std::vector& ignore) { auto is_ignored = [&](bsoncxx::document::value v) { return std::any_of(std::begin(ignore), std::end(ignore), [&](stdx::string_view key) { diff --git a/src/mongocxx/test/spec/operation.cpp b/src/mongocxx/test/spec/operation.cpp index e10d0a1f47..0ff8ca92a0 100644 --- a/src/mongocxx/test/spec/operation.cpp +++ b/src/mongocxx/test/spec/operation.cpp @@ -50,7 +50,7 @@ namespace spec { using namespace mongocxx; using namespace bsoncxx; -int64_t as_int64(const document::element& el) { +static int64_t as_int64(const document::element& el) { if (el.type() == type::k_int32) { return static_cast(el.get_int32().value); } else if (el.type() == type::k_int64) { diff --git a/src/mongocxx/test/spec/unified_tests/assert.cpp b/src/mongocxx/test/spec/unified_tests/assert.cpp index 62223ab4b3..4f95185100 100644 --- a/src/mongocxx/test/spec/unified_tests/assert.cpp +++ b/src/mongocxx/test/spec/unified_tests/assert.cpp @@ -72,8 +72,6 @@ std::string match_doc_current_path() noexcept { return std::accumulate(S_match_doc_path.cbegin(), S_match_doc_path.cend(), std::string()); } -} // namespace - template type to_type(const Element& type) { auto type_str = string::to_string(type.get_string().value); @@ -234,6 +232,8 @@ void matches_array(types::bson_value::view actual, } } +} // namespace + void assert::matches(types::bson_value::view actual, types::bson_value::view expected, entity::map& map, diff --git a/src/mongocxx/test/spec/unified_tests/operations.cpp b/src/mongocxx/test/spec/unified_tests/operations.cpp index cd5df41881..ddbc43b045 100644 --- a/src/mongocxx/test/spec/unified_tests/operations.cpp +++ b/src/mongocxx/test/spec/unified_tests/operations.cpp @@ -35,6 +35,8 @@ using namespace bsoncxx; using builder::basic::kvp; using builder::basic::make_document; +namespace { + int64_t as_int64(const document::element& el) { if (el.type() == type::k_int32) return static_cast(el.get_int32().value); @@ -315,7 +317,7 @@ void set_hint(Model& model, const mongocxx::document::element& hint) { } } -document::value bulk_write(collection& coll, client_session* session, document::view op) { +document::value run_bulk_write(collection& coll, client_session* session, document::view op) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; @@ -1026,59 +1028,6 @@ document::value find_one_and_update(collection& coll, return result.extract(); } -bsoncxx::stdx::optional operations::lookup_read_concern(document::view doc) { - if (doc["readConcern"] && doc["readConcern"]["level"]) { - read_concern rc; - rc.acknowledge_string(string::to_string(doc["readConcern"]["level"].get_string().value)); - return rc; - } - - return {}; -} - -bsoncxx::stdx::optional operations::lookup_write_concern(document::view doc) { - if (doc["writeConcern"] && doc["writeConcern"]["w"]) { - write_concern wc; - document::element w = doc["writeConcern"]["w"]; - if (w.type() == bsoncxx::type::k_string) { - std::string level = string::to_string(w.get_string().value); - if (level == "majority") { - wc.acknowledge_level(write_concern::level::k_majority); - } else if (level == "acknowledged") { - wc.acknowledge_level(write_concern::level::k_acknowledged); - } else if (level == "unacknowledged") { - wc.acknowledge_level(write_concern::level::k_unacknowledged); - } - } else if (w.type() == bsoncxx::type::k_int32) { - wc.nodes(w.get_int32()); - } - return wc; - } - - return {}; -} - -bsoncxx::stdx::optional operations::lookup_read_preference(document::view doc) { - if (doc["readPreference"] && doc["readPreference"]["mode"]) { - read_preference rp; - std::string mode = string::to_string(doc["readPreference"]["mode"].get_string().value); - if (mode == "Primary") { - rp.mode(read_preference::read_mode::k_primary); - } else if (mode == "PrimaryPreferred") { - rp.mode(read_preference::read_mode::k_primary_preferred); - } else if (mode == "Secondary") { - rp.mode(read_preference::read_mode::k_secondary); - } else if (mode == "SecondaryPreferred") { - rp.mode(read_preference::read_mode::k_secondary_preferred); - } else if (mode == "Nearest") { - rp.mode(read_preference::read_mode::k_nearest); - } - return rp; - } - - return {}; -} - options::transaction set_opts(document::view args) { options::transaction txn_opts; @@ -1894,6 +1843,8 @@ document::value update_search_index(collection& coll, document::view operation) return make_document(); } +} // namespace + document::value operations::run(entity::map& entity_map, std::unordered_map& apm_map, const array::element& op, @@ -1907,7 +1858,7 @@ document::value operations::run(entity::map& entity_map, if (name == "find") return find(entity_map.get_collection(object), get_session(op_view, entity_map), op_view); if (name == "bulkWrite") - return bulk_write( + return run_bulk_write( entity_map.get_collection(object), get_session(op_view, entity_map), op_view); if (name == "insertMany") return insert_many( @@ -2300,4 +2251,57 @@ document::value operations::run(entity::map& entity_map, throw std::logic_error{"unsupported operation: " + name}; } +bsoncxx::stdx::optional operations::lookup_read_concern(document::view doc) { + if (doc["readConcern"] && doc["readConcern"]["level"]) { + read_concern rc; + rc.acknowledge_string(string::to_string(doc["readConcern"]["level"].get_string().value)); + return rc; + } + + return {}; +} + +bsoncxx::stdx::optional operations::lookup_write_concern(document::view doc) { + if (doc["writeConcern"] && doc["writeConcern"]["w"]) { + write_concern wc; + document::element w = doc["writeConcern"]["w"]; + if (w.type() == bsoncxx::type::k_string) { + std::string level = string::to_string(w.get_string().value); + if (level == "majority") { + wc.acknowledge_level(write_concern::level::k_majority); + } else if (level == "acknowledged") { + wc.acknowledge_level(write_concern::level::k_acknowledged); + } else if (level == "unacknowledged") { + wc.acknowledge_level(write_concern::level::k_unacknowledged); + } + } else if (w.type() == bsoncxx::type::k_int32) { + wc.nodes(w.get_int32()); + } + return wc; + } + + return {}; +} + +bsoncxx::stdx::optional operations::lookup_read_preference(document::view doc) { + if (doc["readPreference"] && doc["readPreference"]["mode"]) { + read_preference rp; + std::string mode = string::to_string(doc["readPreference"]["mode"].get_string().value); + if (mode == "Primary") { + rp.mode(read_preference::read_mode::k_primary); + } else if (mode == "PrimaryPreferred") { + rp.mode(read_preference::read_mode::k_primary_preferred); + } else if (mode == "Secondary") { + rp.mode(read_preference::read_mode::k_secondary); + } else if (mode == "SecondaryPreferred") { + rp.mode(read_preference::read_mode::k_secondary_preferred); + } else if (mode == "Nearest") { + rp.mode(read_preference::read_mode::k_nearest); + } + return rp; + } + + return {}; +} + } // namespace mongocxx diff --git a/src/mongocxx/test/spec/util.cpp b/src/mongocxx/test/spec/util.cpp index 1cbeda2d36..e7ef070485 100644 --- a/src/mongocxx/test/spec/util.cpp +++ b/src/mongocxx/test/spec/util.cpp @@ -230,7 +230,7 @@ void disable_fail_point(std::string uri_string, disable_fail_point(client, fail_point); } -void disable_targeted_fail_point(std::uint32_t server_id) { +static void disable_targeted_fail_point(std::uint32_t server_id) { const auto command_owner = make_document(kvp("configureFailPoint", "failCommand"), kvp("mode", "off")); const auto command = command_owner.view(); @@ -597,7 +597,7 @@ static void test_setup(document::view test, document::view test_spec) { configure_fail_point(client, test); } -void parse_session_opts(document::view session_opts, options::client_session* out) { +static void parse_session_opts(document::view session_opts, options::client_session* out) { options::transaction txn_opts; if (session_opts["defaultTransactionOptions"]) { if (auto rc = @@ -627,8 +627,7 @@ void parse_session_opts(document::view session_opts, options::client_session* ou out->default_transaction_opts(txn_opts); } -using bsoncxx::stdx::string_view; -void run_transaction_operations( +static void run_transaction_operations( document::view test, client* client, string_view db_name, From 576de97557c5ab130cfb55b53611c3c74585c1da Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:42 -0500 Subject: [PATCH 03/16] Address -Wold-style-cast warnings --- ...tic_client_side_field_level_encryption.cpp | 5 ++-- examples/mongocxx/explicit_encryption.cpp | 5 ++-- .../explicit_encryption_auto_decryption.cpp | 5 ++-- ...ide_field_level_encryption_enforcement.cpp | 5 ++-- src/bsoncxx/test/bson_builder.cpp | 23 ++++++++++----- src/bsoncxx/test/bson_value.cpp | 7 +++-- src/mongocxx/test/client.cpp | 2 +- src/mongocxx/test/client_session.cpp | 8 +++-- src/mongocxx/test/client_side_encryption.cpp | 29 +++++++++++-------- src/mongocxx/test/collection.cpp | 4 +-- src/mongocxx/test/index_view.cpp | 16 ++++++---- src/mongocxx/test/spec/monitoring.cpp | 2 +- .../test/spec/unified_tests/runner.cpp | 2 +- 13 files changed, 68 insertions(+), 45 deletions(-) diff --git a/examples/mongocxx/automatic_client_side_field_level_encryption.cpp b/examples/mongocxx/automatic_client_side_field_level_encryption.cpp index 88ff992d69..a47dc397b3 100644 --- a/examples/mongocxx/automatic_client_side_field_level_encryption.cpp +++ b/examples/mongocxx/automatic_client_side_field_level_encryption.cpp @@ -103,8 +103,9 @@ int main() { // the encryption key; here, we use a random key as a placeholder. char key_storage[kKeyLength]; std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{ - bsoncxx::binary_sub_type::k_binary, kKeyLength, (const uint8_t*)&key_storage}; + bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, + kKeyLength, + reinterpret_cast(&key_storage)}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/examples/mongocxx/explicit_encryption.cpp b/examples/mongocxx/explicit_encryption.cpp index f661a4707a..022a47f64b 100644 --- a/examples/mongocxx/explicit_encryption.cpp +++ b/examples/mongocxx/explicit_encryption.cpp @@ -51,8 +51,9 @@ int main() { // the encryption key; here, we use a random key as a placeholder. char key_storage[kKeyLength]; std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{ - bsoncxx::binary_sub_type::k_binary, kKeyLength, (const uint8_t*)&key_storage}; + bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, + kKeyLength, + reinterpret_cast(&key_storage)}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/examples/mongocxx/explicit_encryption_auto_decryption.cpp b/examples/mongocxx/explicit_encryption_auto_decryption.cpp index d89213144b..125e7b6115 100644 --- a/examples/mongocxx/explicit_encryption_auto_decryption.cpp +++ b/examples/mongocxx/explicit_encryption_auto_decryption.cpp @@ -51,8 +51,9 @@ int main() { // the encryption key; here, we use a random key as a placeholder. char key_storage[kKeyLength]; std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{ - bsoncxx::binary_sub_type::k_binary, kKeyLength, (const uint8_t*)&key_storage}; + bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, + kKeyLength, + reinterpret_cast(&key_storage)}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp b/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp index 8504608b41..146f48c890 100644 --- a/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp +++ b/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp @@ -53,8 +53,9 @@ int main() { // the encryption key; here, we use a random key as a placeholder. char key_storage[kKeyLength]; std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{ - bsoncxx::binary_sub_type::k_binary, kKeyLength, (const uint8_t*)&key_storage}; + bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, + kKeyLength, + reinterpret_cast(&key_storage)}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/src/bsoncxx/test/bson_builder.cpp b/src/bsoncxx/test/bson_builder.cpp index 134af723af..493721c4f8 100644 --- a/src/bsoncxx/test/bson_builder.cpp +++ b/src/bsoncxx/test/bson_builder.cpp @@ -141,11 +141,14 @@ TEST_CASE("builder appends binary", "[bsoncxx::builder::stream]") { bson_t expected; bson_init(&expected); - bson_append_binary(&expected, "foo", -1, BSON_SUBTYPE_BINARY, (uint8_t*)"deadbeef", 8); + bson_append_binary( + &expected, "foo", -1, BSON_SUBTYPE_BINARY, reinterpret_cast("deadbeef"), 8); builder::stream::document b; - b << "foo" << types::b_binary{binary_sub_type::k_binary, 8, (uint8_t*)"deadbeef"}; + b << "foo" + << types::b_binary{ + binary_sub_type::k_binary, 8, reinterpret_cast("deadbeef")}; bson_eq_stream(&expected, b); @@ -179,13 +182,13 @@ TEST_CASE("builder appends oid", "[bsoncxx::builder::stream]") { builder::stream::document b; SECTION("b_oid works") { - b << "foo" << types::b_oid{bsoncxx::oid{(char*)oid.bytes, 12}}; + b << "foo" << types::b_oid{bsoncxx::oid{reinterpret_cast(oid.bytes), 12}}; bson_eq_stream(&expected, b); } SECTION("raw oid works") { - b << "foo" << bsoncxx::oid{(char*)oid.bytes, 12}; + b << "foo" << bsoncxx::oid{reinterpret_cast(oid.bytes), 12}; bson_eq_stream(&expected, b); } @@ -1312,9 +1315,12 @@ TEST_CASE("list builder appends binary", "[bsoncxx::builder::list]") { bson_t expected; bson_init(&expected); - bson_append_binary(&expected, "foo", -1, BSON_SUBTYPE_BINARY, (uint8_t*)"data", 4); + bson_append_binary( + &expected, "foo", -1, BSON_SUBTYPE_BINARY, reinterpret_cast("data"), 4); - builder::list b{"foo", types::b_binary{binary_sub_type::k_binary, 4, (uint8_t*)"data"}}; + builder::list b{ + "foo", + types::b_binary{binary_sub_type::k_binary, 4, reinterpret_cast("data")}}; bson_eq_object(&expected, b.view().get_document().value); @@ -1344,13 +1350,14 @@ TEST_CASE("list builder appends oid", "[bsoncxx::builder::list]") { bson_append_oid(&expected, "foo", -1, &oid); SECTION("b_oid works") { - builder::list b{"foo", types::b_oid{bsoncxx::oid{(char*)oid.bytes, 12}}}; + builder::list b{"foo", + types::b_oid{bsoncxx::oid{reinterpret_cast(oid.bytes), 12}}}; bson_eq_object(&expected, b.view().get_document().value); } SECTION("raw oid works") { - builder::list b{"foo", bsoncxx::oid{(char*)oid.bytes, 12}}; + builder::list b{"foo", bsoncxx::oid{reinterpret_cast(oid.bytes), 12}}; bson_eq_object(&expected, b.view().get_document().value); } diff --git a/src/bsoncxx/test/bson_value.cpp b/src/bsoncxx/test/bson_value.cpp index 30bbbd4f20..db2ba0b889 100644 --- a/src/bsoncxx/test/bson_value.cpp +++ b/src/bsoncxx/test/bson_value.cpp @@ -248,12 +248,13 @@ TEST_CASE("types::bson_value::value", "[bsoncxx::types::bson_value::value]") { SECTION("binary") { std::vector bin{'d', 'e', 'a', 'd', 'b', 'e', 'e', 'f'}; auto test_doc = bson_value::make_value( - b_binary{binary_sub_type::k_binary, (uint32_t)bin.size(), bin.data()}); + b_binary{binary_sub_type::k_binary, static_cast(bin.size()), bin.data()}); value_construction_test(test_doc.view()); coverting_construction_test(bin, test_doc); - REQUIRE(bson_value::value(b_binary{ - binary_sub_type::k_binary, (uint32_t)bin.size(), bin.data()}) == test_doc); + REQUIRE(bson_value::value(b_binary{binary_sub_type::k_binary, + static_cast(bin.size()), + bin.data()}) == test_doc); REQUIRE(bson_value::value(bin.data(), bin.size(), binary_sub_type::k_binary) == test_doc); REQUIRE(bson_value::value(bin.data(), bin.size()) == test_doc); diff --git a/src/mongocxx/test/client.cpp b/src/mongocxx/test/client.cpp index 0ceacda416..d5d2f828a3 100644 --- a/src/mongocxx/test/client.cpp +++ b/src/mongocxx/test/client.cpp @@ -144,7 +144,7 @@ TEST_CASE("A client throws if its underlying mongoc client is NULL", "[client]") instance::current(); - client_new->interpose([](const mongoc_uri_t*) { return (mongoc_client_t*)nullptr; }); + client_new->interpose([](const mongoc_uri_t*) -> mongoc_client_t* { return nullptr; }); REQUIRE_THROWS_AS(client{uri{}}, mongocxx::exception); } diff --git a/src/mongocxx/test/client_session.cpp b/src/mongocxx/test/client_session.cpp index cd5edc4218..ac8f67ba09 100644 --- a/src/mongocxx/test/client_session.cpp +++ b/src/mongocxx/test/client_session.cpp @@ -160,9 +160,11 @@ TEST_CASE("start_session failure", "[session]") { instance::current(); client_start_session - ->interpose([](mongoc_client_t*, const mongoc_session_opt_t*, bson_error_t* error) { + ->interpose([](mongoc_client_t*, + const mongoc_session_opt_t*, + bson_error_t* error) -> mongoc_client_session_t* { bson_set_error(error, MONGOC_ERROR_CLIENT, MONGOC_ERROR_CLIENT_SESSION_FAILURE, "foo"); - return (mongoc_client_session_t*)nullptr; + return nullptr; }) .forever(); @@ -419,7 +421,7 @@ TEST_CASE("lsid", "[session]") { auto one = bsoncxx::types::bson_value::view{bsoncxx::types::b_int32{1}}; auto two = bsoncxx::types::bson_value::view{bsoncxx::types::b_int32{2}}; - auto data = (uint8_t*)"foo"; + auto data = reinterpret_cast("foo"); size_t len = 4; // Ensure multiple chunks. options::gridfs::upload opts; diff --git a/src/mongocxx/test/client_side_encryption.cpp b/src/mongocxx/test/client_side_encryption.cpp index d7ffbc0dc6..5a55f67078 100644 --- a/src/mongocxx/test/client_side_encryption.cpp +++ b/src/mongocxx/test/client_side_encryption.cpp @@ -152,7 +152,7 @@ bsoncxx::document::value _make_kms_doc(bool include_external = true) { memcpy(&(key_storage[0]), kLocalMasterKey, 96); bsoncxx::types::b_binary local_master_key{ - bsoncxx::binary_sub_type::k_binary, 96, (const uint8_t*)&key_storage}; + bsoncxx::binary_sub_type::k_binary, 96, reinterpret_cast(&key_storage)}; kms_doc.append( kvp("local", [&](sub_document subdoc) { subdoc.append(kvp("key", local_master_key)); })); @@ -867,16 +867,21 @@ void _run_corpus_test(bool use_schema_map) { memcpy(&(gcp_key_id_storage[0]), kGcpKeyUUID, 16); memcpy(&(kmip_key_id_storage[0]), kKmipKeyUUID, 16); - bsoncxx::types::b_binary local_key_id{ - bsoncxx::binary_sub_type::k_uuid, 16, (const uint8_t*)&local_key_id_storage}; - bsoncxx::types::b_binary aws_key_id{ - bsoncxx::binary_sub_type::k_uuid, 16, (const uint8_t*)&aws_key_id_storage}; - bsoncxx::types::b_binary azure_key_id{ - bsoncxx::binary_sub_type::k_uuid, 16, (const uint8_t*)&azure_key_id_storage}; - bsoncxx::types::b_binary gcp_key_id{ - bsoncxx::binary_sub_type::k_uuid, 16, (const uint8_t*)&gcp_key_id_storage}; - bsoncxx::types::b_binary kmip_key_id{ - bsoncxx::binary_sub_type::k_uuid, 16, (const uint8_t*)&kmip_key_id_storage}; + bsoncxx::types::b_binary local_key_id{bsoncxx::binary_sub_type::k_uuid, + 16, + reinterpret_cast(&local_key_id_storage)}; + bsoncxx::types::b_binary aws_key_id{bsoncxx::binary_sub_type::k_uuid, + 16, + reinterpret_cast(&aws_key_id_storage)}; + bsoncxx::types::b_binary azure_key_id{bsoncxx::binary_sub_type::k_uuid, + 16, + reinterpret_cast(&azure_key_id_storage)}; + bsoncxx::types::b_binary gcp_key_id{bsoncxx::binary_sub_type::k_uuid, + 16, + reinterpret_cast(&gcp_key_id_storage)}; + bsoncxx::types::b_binary kmip_key_id{bsoncxx::binary_sub_type::k_uuid, + 16, + reinterpret_cast(&kmip_key_id_storage)}; auto local_key_value = make_value(local_key_id); auto aws_key_value = make_value(aws_key_id); @@ -2841,7 +2846,7 @@ TEST_CASE("Custom Key Material Test", "[client_side_encryption]") { std::vector id = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; bsoncxx::types::b_binary id_bin{ - bsoncxx::binary_sub_type::k_uuid, (uint32_t)id.size(), id.data()}; + bsoncxx::binary_sub_type::k_uuid, static_cast(id.size()), id.data()}; auto key_doc = make_document(kvp("_id", id_bin)); mongocxx::libbson::scoped_bson_t bson_doc; diff --git a/src/mongocxx/test/collection.cpp b/src/mongocxx/test/collection.cpp index 7a6c549150..9ec735ee38 100644 --- a/src/mongocxx/test/collection.cpp +++ b/src/mongocxx/test/collection.cpp @@ -829,7 +829,7 @@ TEST_CASE("CRUD functionality", "[driver::collection]") { REQUIRE(updated); REQUIRE(updated->view()["changed"].get_bool() == true); - REQUIRE(coll.count_documents({}) == (std::int64_t)1); + REQUIRE(coll.count_documents({}) == std::int64_t{1}); } SECTION("matching upsert updates document", "[collection]") { @@ -978,7 +978,7 @@ TEST_CASE("CRUD functionality", "[driver::collection]") { coll.delete_one(b2.view()); - REQUIRE(coll.count_documents({}) == (std::int64_t)2); + REQUIRE(coll.count_documents({}) == std::int64_t{2}); auto cursor = coll.find({}); diff --git a/src/mongocxx/test/index_view.cpp b/src/mongocxx/test/index_view.cpp index bdbe58309a..9ec1b4a2e9 100644 --- a/src/mongocxx/test/index_view.cpp +++ b/src/mongocxx/test/index_view.cpp @@ -401,9 +401,11 @@ TEST_CASE("drop_all", "[index_view]") { } auto cursor1 = indexes.list(); - REQUIRE((unsigned)std::distance(cursor1.begin(), cursor1.end()) == models.size() + 1); - REQUIRE((unsigned)(result_view["numIndexesAfter"].get_int32() - - result_view["numIndexesBefore"].get_int32()) == models.size()); + REQUIRE(static_cast(std::distance(cursor1.begin(), cursor1.end())) == + models.size() + 1); + REQUIRE(static_cast(result_view["numIndexesAfter"].get_int32() - + result_view["numIndexesBefore"].get_int32()) == + models.size()); indexes.drop_all(); auto cursor2 = indexes.list(); @@ -430,9 +432,11 @@ TEST_CASE("drop_all", "[index_view]") { } auto cursor1 = indexes.list(); - REQUIRE((unsigned)std::distance(cursor1.begin(), cursor1.end()) == models.size() + 1); - REQUIRE((unsigned)(result_view["numIndexesAfter"].get_int32() - - result_view["numIndexesBefore"].get_int32()) == models.size()); + REQUIRE(static_cast(std::distance(cursor1.begin(), cursor1.end())) == + models.size() + 1u); + REQUIRE(static_cast(result_view["numIndexesAfter"].get_int32() - + result_view["numIndexesBefore"].get_int32()) == + models.size()); options::index_view options; options.max_time(std::chrono::milliseconds(1)); diff --git a/src/mongocxx/test/spec/monitoring.cpp b/src/mongocxx/test/spec/monitoring.cpp index c00663e4b9..60ab82caf4 100644 --- a/src/mongocxx/test/spec/monitoring.cpp +++ b/src/mongocxx/test/spec/monitoring.cpp @@ -33,7 +33,7 @@ using namespace mongocxx; using bsoncxx::to_json; static void remove_ignored_command_monitoring_events(apm_checker::event_vector& events, - const std::vector& ignore) { + const std::vector& ignore) { auto is_ignored = [&](bsoncxx::document::value v) { return std::any_of(std::begin(ignore), std::end(ignore), [&](stdx::string_view key) { return v.view()["commandStartedEvent"]["command"][key] || diff --git a/src/mongocxx/test/spec/unified_tests/runner.cpp b/src/mongocxx/test/spec/unified_tests/runner.cpp index 38a4767496..c11a058118 100644 --- a/src/mongocxx/test/spec/unified_tests/runner.cpp +++ b/src/mongocxx/test/spec/unified_tests/runner.cpp @@ -86,7 +86,7 @@ bsoncxx::document::value get_kms_values() { char key_storage[96]; memcpy(&(key_storage[0]), kLocalMasterKey, 96); const bsoncxx::types::b_binary local_master_key{ - bsoncxx::binary_sub_type::k_binary, 96, (const uint8_t*)&key_storage}; + bsoncxx::binary_sub_type::k_binary, 96, reinterpret_cast(&key_storage)}; auto kms_doc = make_document( kvp("aws", From 54317b2d397f20c3dae25e4cb4e23b0237cc6493 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:43 -0500 Subject: [PATCH 04/16] Address -Wmissing-noreturn warnings --- examples/mongocxx/change_streams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mongocxx/change_streams.cpp b/examples/mongocxx/change_streams.cpp index 16f66d844f..f56be96a9c 100644 --- a/examples/mongocxx/change_streams.cpp +++ b/examples/mongocxx/change_streams.cpp @@ -29,7 +29,7 @@ namespace { // watch_forever iterates the change stream until an error occurs. -void watch_forever(mongocxx::collection& collection) { +[[noreturn]] void watch_forever(mongocxx::collection& collection) { mongocxx::options::change_stream options; // Wait up to 1 second before polling again. const std::chrono::milliseconds await_time{1000}; From d14362c713bb966be17a10b51c99c78724d8177f Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:43 -0500 Subject: [PATCH 05/16] Address -Wsuggest-override warnings --- examples/mongocxx/instance_management.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/mongocxx/instance_management.cpp b/examples/mongocxx/instance_management.cpp index dae68ba911..8007235868 100644 --- a/examples/mongocxx/instance_management.cpp +++ b/examples/mongocxx/instance_management.cpp @@ -73,9 +73,9 @@ class mongo_access { void configure(mongocxx::uri uri) { class noop_logger : public mongocxx::logger { public: - virtual void operator()(mongocxx::log_level, - bsoncxx::stdx::string_view, - bsoncxx::stdx::string_view) noexcept {} + void operator()(mongocxx::log_level, + bsoncxx::stdx::string_view, + bsoncxx::stdx::string_view) noexcept override {} }; // Use `std::make_unique` with C++14 and newer. From dfe971c85189de85a393f675f9c6b7a37a240e69 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:43 -0500 Subject: [PATCH 06/16] Address -Wreserved-identifier warnings --- examples/mongocxx/mongodb.com/documentation_examples.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/mongocxx/mongodb.com/documentation_examples.cpp b/examples/mongocxx/mongodb.com/documentation_examples.cpp index 8effb86d44..2dc7bac778 100644 --- a/examples/mongocxx/mongodb.com/documentation_examples.cpp +++ b/examples/mongocxx/mongodb.com/documentation_examples.cpp @@ -140,7 +140,7 @@ std::string getenv_or_fail(const char* s) { // Returns a document with credentials for KMS providers. // If include_external is true, all KMS providers are set. // If include_external is false, only the local provider is set. -bsoncxx::document::value _make_kms_doc(bool include_external = true) { +bsoncxx::document::value make_kms_doc(bool include_external = true) { using bsoncxx::builder::basic::sub_document; using bsoncxx::builder::stream::close_array; using bsoncxx::builder::stream::close_document; @@ -1611,7 +1611,7 @@ static void queryable_encryption_api(mongocxx::client& client) { options::client_encryption ce_opts; ce_opts.key_vault_client(&key_vault_client); ce_opts.key_vault_namespace({"keyvault", "datakeys"}); - ce_opts.kms_providers(_make_kms_doc(false)); + ce_opts.kms_providers(make_kms_doc(false)); client_encryption client_encryption(std::move(ce_opts)); auto key1_id = client_encryption.create_data_key("local"); @@ -1633,7 +1633,7 @@ static void queryable_encryption_api(mongocxx::client& client) { // Create an Queryable Encryption collection. options::auto_encryption auto_encrypt_opts{}; auto_encrypt_opts.key_vault_namespace({"keyvault", "datakeys"}); - auto_encrypt_opts.kms_providers(_make_kms_doc(false)); + auto_encrypt_opts.kms_providers(make_kms_doc(false)); auto_encrypt_opts.encrypted_fields_map(encrypted_fields_map.view()); // Optional, If mongocryptd is not in PATH, then find the binary at MONGOCRYPTD_PATH. From a85cb61e09525f33b0b5cc38e200fb3a2ce3e2cd Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:44 -0500 Subject: [PATCH 07/16] Address -Wunreachable-code-return warnings --- examples/mongocxx/mongodb.com/documentation_examples.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/mongocxx/mongodb.com/documentation_examples.cpp b/examples/mongocxx/mongodb.com/documentation_examples.cpp index 2dc7bac778..3b151224e8 100644 --- a/examples/mongocxx/mongodb.com/documentation_examples.cpp +++ b/examples/mongocxx/mongodb.com/documentation_examples.cpp @@ -1441,19 +1441,19 @@ static bool is_snapshot_ready(mongocxx::client& client, mongocxx::collection& co opts.snapshot(true); auto session = client.start_session(opts); + try { - auto maybe_value = collection.find_one(session, {}); - if (maybe_value) { + if (collection.find_one(session, {})) { return true; } - return false; } catch (const mongocxx::operation_exception& e) { if (e.code().value() == 246) { // snapshot unavailable return false; } throw; } - return true; + + return false; } // Seed the pets database and wait for the snapshot to become available. From 288e8de4c1a86c9f5b24d0a7ee398a623a5062bd Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:44 -0500 Subject: [PATCH 08/16] Address -Wfloat-equal warnings --- examples/mongocxx/mongodb.com/runcommand_examples.cpp | 2 +- src/mongocxx/test/client_helpers.cpp | 8 +++++++- src/mongocxx/test/spec/unified_tests/assert.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/mongocxx/mongodb.com/runcommand_examples.cpp b/examples/mongocxx/mongodb.com/runcommand_examples.cpp index ca282852d1..fd172bcf85 100644 --- a/examples/mongocxx/mongodb.com/runcommand_examples.cpp +++ b/examples/mongocxx/mongodb.com/runcommand_examples.cpp @@ -28,7 +28,7 @@ void runcommand_examples(mongocxx::database& db) { auto buildInfo = db.run_command(make_document(kvp("buildInfo", 1))); // End runCommand Example 1 - if (buildInfo.view()["ok"].get_double() != double{1}) { + if (buildInfo.view()["ok"].get_double() != 1.0) { throw std::logic_error("buildInfo command failed in runCommand example 1"); } } diff --git a/src/mongocxx/test/client_helpers.cpp b/src/mongocxx/test/client_helpers.cpp index d745408f25..c258f07d8a 100644 --- a/src/mongocxx/test/client_helpers.cpp +++ b/src/mongocxx/test/client_helpers.cpp @@ -38,6 +38,7 @@ #include #include +#include #include namespace mongocxx { @@ -343,7 +344,10 @@ bool matches(types::bson_value::view main, return t == main.type(); } - if (is_numeric(pattern) && as_double(pattern) == 42) { + BSONCXX_PUSH_WARNINGS(); + BSONCXX_DISABLE_WARNING(GNU("-Wfloat-equal")); + + if (is_numeric(pattern) && as_double(pattern) == 42.0) { return true; } @@ -352,6 +356,8 @@ bool matches(types::bson_value::view main, return true; } + BSONCXX_POP_WARNINGS(); + if (main.type() == type::k_document) { // the value '42' acts as placeholders for "any value" if (pattern.type() == type::k_string && 0 == pattern.get_string().value.compare("42")) { diff --git a/src/mongocxx/test/spec/unified_tests/assert.cpp b/src/mongocxx/test/spec/unified_tests/assert.cpp index 4f95185100..c9ab4953e1 100644 --- a/src/mongocxx/test/spec/unified_tests/assert.cpp +++ b/src/mongocxx/test/spec/unified_tests/assert.cpp @@ -27,6 +27,8 @@ #include #include +#include + using namespace bsoncxx; using namespace mongocxx; @@ -255,8 +257,12 @@ void assert::matches(types::bson_value::view actual, to_string(actual), to_string(expected), match_doc_current_path()); + + BSONCXX_PUSH_WARNINGS(); + BSONCXX_DISABLE_WARNING(GNU("-Wfloat-equal")); REQUIRE(test_util::is_numeric(actual)); REQUIRE(test_util::as_double(expected) == test_util::as_double(actual)); + BSONCXX_POP_WARNINGS(); return; } default: { From 05496abe1abd23011c9da01eaf12e078a53deb31 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:44 -0500 Subject: [PATCH 09/16] Address -Wunused-exception-parameter warnings --- examples/bsoncxx/decimal128.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bsoncxx/decimal128.cpp b/examples/bsoncxx/decimal128.cpp index 380110e72a..513424f4b3 100644 --- a/examples/bsoncxx/decimal128.cpp +++ b/examples/bsoncxx/decimal128.cpp @@ -27,7 +27,7 @@ int main() { decimal128 d128; try { d128 = decimal128{"1.234E+3456"}; - } catch (const bsoncxx::exception& e) { + } catch (const bsoncxx::exception&) { // The example won't fail, but in general, arbitrary strings // might not convert properly. return EXIT_FAILURE; From 71e8137bc5d4e425e79fac04f8446bbcac4f2a62 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:45 -0500 Subject: [PATCH 10/16] Address -Wswitch-enum warnings --- examples/bsoncxx/view_and_value.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/bsoncxx/view_and_value.cpp b/examples/bsoncxx/view_and_value.cpp index 4bc1fd9d88..5c549bdadc 100644 --- a/examples/bsoncxx/view_and_value.cpp +++ b/examples/bsoncxx/view_and_value.cpp @@ -29,6 +29,10 @@ #include #include +#include + +BSONCXX_DISABLE_WARNING(GNU("-Wswitch-enum")); + using namespace bsoncxx; int main() { From fd40ffb459a4e0034c29dc15f9f7d11aa42c6bd8 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 09:02:45 -0500 Subject: [PATCH 11/16] Address -Wunused* warnings --- examples/mongocxx/instance_management.cpp | 4 ---- src/bsoncxx/test/bson_serialization.cpp | 3 --- src/bsoncxx/test/optional.test.cpp | 11 +++++++++++ src/bsoncxx/test/type_traits.test.cpp | 9 +++++---- src/mongocxx/test/spec/command_monitoring.cpp | 2 +- src/mongocxx/test/spec/operation.cpp | 3 +++ src/mongocxx/test/spec/retryable-reads.cpp | 1 + src/mongocxx/test/spec/uri_options.cpp | 1 + 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/examples/mongocxx/instance_management.cpp b/examples/mongocxx/instance_management.cpp index 8007235868..9255a40ff6 100644 --- a/examples/mongocxx/instance_management.cpp +++ b/examples/mongocxx/instance_management.cpp @@ -56,10 +56,6 @@ class mongo_access { return _pool->acquire(); } - bsoncxx::stdx::optional try_get_connection() { - return _pool->try_acquire(); - } - private: mongo_access() = default; diff --git a/src/bsoncxx/test/bson_serialization.cpp b/src/bsoncxx/test/bson_serialization.cpp index c95f5b9db4..1a91b83b24 100644 --- a/src/bsoncxx/test/bson_serialization.cpp +++ b/src/bsoncxx/test/bson_serialization.cpp @@ -36,9 +36,6 @@ struct Person { bool operator==(const Person& rhs) const { return (first_name == rhs.first_name) && (last_name == rhs.last_name) && (age == rhs.age); } - bool operator!=(const Person& rhs) const { - return !(operator==(rhs)); - } }; void to_bson(const Person& person, bsoncxx::document::value& bson_object) { diff --git a/src/bsoncxx/test/optional.test.cpp b/src/bsoncxx/test/optional.test.cpp index d3de72e132..7d9858b309 100644 --- a/src/bsoncxx/test/optional.test.cpp +++ b/src/bsoncxx/test/optional.test.cpp @@ -51,6 +51,11 @@ template struct is_hashable : std::false_type {}; #endif +BSONCXX_PUSH_WARNINGS(); +BSONCXX_DISABLE_WARNING(GNU("-Wunused")); +BSONCXX_DISABLE_WARNING(Clang("-Wunused-member-function")); +BSONCXX_DISABLE_WARNING(Clang("-Wunneeded-member-function")); + struct not_default_constructible { explicit not_default_constructible(int); }; @@ -76,10 +81,16 @@ struct not_copyable { not_copyable& operator=(not_copyable&&) = default; }; +BSONCXX_POP_WARNINGS(); + // Improve quality of error messages on failure (in particular for MSVC). #define STATIC_ASSERT_EXPR(expr) static_assert((expr), "expected: " #expr) #define STATIC_ASSERT_EXPR_EQUAL(a, b) static_assert((a) == (b), "expected: " #a " == " #b) + +BSONCXX_PUSH_WARNINGS(); +BSONCXX_DISABLE_WARNING(GNU("-Wunused-macros")); #define STATIC_ASSERT_EXPR_IMPLIES(a, b) static_assert((!(a) || (b)), "expected: " #a " -> " #b) +BSONCXX_POP_WARNINGS(); #if defined(BSONCXX_POLY_USE_STD) // Deliberately weaken assertions for stdlib implementations to accomodate for differences in diff --git a/src/bsoncxx/test/type_traits.test.cpp b/src/bsoncxx/test/type_traits.test.cpp index dc14cbbefa..54190a0f1c 100644 --- a/src/bsoncxx/test/type_traits.test.cpp +++ b/src/bsoncxx/test/type_traits.test.cpp @@ -8,6 +8,7 @@ // We declare variables that are only used for compilation checking BSONCXX_DISABLE_WARNING(GNU("-Wunused")); +BSONCXX_DISABLE_WARNING(Clang("-Wunused-template")); namespace { @@ -159,7 +160,9 @@ static_assert( struct constrained_callable { // Viable only if F is callable as F(int, Arg) template - tt::requires_t> operator()(F&&, Arg) const; + tt::requires_t> operator()(F&&, Arg) const { + return 0.0; + } }; static_assert(!tt::is_detected - constexpr int val(T x, bsoncxx::detail::rank<0>) const { - return x.never_instantiated(); - } + constexpr int val(T x, bsoncxx::detail::rank<0>) const = delete; template constexpr int val(T x, bsoncxx::detail::rank<1>) const { return x + 30; diff --git a/src/mongocxx/test/spec/command_monitoring.cpp b/src/mongocxx/test/spec/command_monitoring.cpp index d82f13388d..b360a6253b 100644 --- a/src/mongocxx/test/spec/command_monitoring.cpp +++ b/src/mongocxx/test/spec/command_monitoring.cpp @@ -182,7 +182,7 @@ void run_command_monitoring_tests_in_file(std::string test_path) { try { op_runner.run(operation); - } catch (mongocxx::exception& e) { + } catch (mongocxx::exception&) { // do nothing. } diff --git a/src/mongocxx/test/spec/operation.cpp b/src/mongocxx/test/spec/operation.cpp index 0ff8ca92a0..b8c88b85c0 100644 --- a/src/mongocxx/test/spec/operation.cpp +++ b/src/mongocxx/test/spec/operation.cpp @@ -704,6 +704,7 @@ document::value operation_runner::_run_replace_one(document::view operation) { try { modified_count = replace_result->modified_count(); } catch (const std::exception& e) { + CAPTURE(e); } upserted_count = replace_result->result().upserted_count(); @@ -796,6 +797,7 @@ document::value operation_runner::_run_update_many(document::view operation) { try { modified_count = update_result->modified_count(); } catch (const std::exception& e) { + CAPTURE(e); } upserted_count = update_result->result().upserted_count(); @@ -887,6 +889,7 @@ document::value operation_runner::_run_update_one(document::view operation) { try { modified_count = update_result->modified_count(); } catch (const std::exception& e) { + CAPTURE(e); } upserted_count = update_result->result().upserted_count(); diff --git a/src/mongocxx/test/spec/retryable-reads.cpp b/src/mongocxx/test/spec/retryable-reads.cpp index 2bef0a6c40..e1a8b98b1c 100644 --- a/src/mongocxx/test/spec/retryable-reads.cpp +++ b/src/mongocxx/test/spec/retryable-reads.cpp @@ -99,6 +99,7 @@ void run_retryable_reads_tests_in_file(std::string test_path) { try { actual_outcome_value = op_runner.run(operation); } catch (const operation_exception& e) { + CAPTURE(e); REQUIRE(operation["error"].get_bool().value); } diff --git a/src/mongocxx/test/spec/uri_options.cpp b/src/mongocxx/test/spec/uri_options.cpp index 8adea2430a..6e60955acb 100644 --- a/src/mongocxx/test/spec/uri_options.cpp +++ b/src/mongocxx/test/spec/uri_options.cpp @@ -114,6 +114,7 @@ TEST_CASE("uri_options::test_srv_options", "[uri_options]") { } } catch (mongocxx::logic_error& e) { bool should_throw = !test.valid || test.warning; + CAPTURE(e); REQUIRE(should_throw); } } From ad3b3109234e7421b8540edc54233c8082b82900 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 29 Aug 2024 13:22:56 -0500 Subject: [PATCH 12/16] Address "hides previous local declaration" warnings (C4456) --- examples/bsoncxx/view_and_value.cpp | 15 +++++----- .../mongocxx/get_values_from_documents.cpp | 6 ++-- .../mongocxx/v_noabi/mongocxx/collection.cpp | 8 ++--- src/mongocxx/test/client_side_encryption.cpp | 30 +++++++------------ src/mongocxx/test/database.cpp | 1 - 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/examples/bsoncxx/view_and_value.cpp b/examples/bsoncxx/view_and_value.cpp index 5c549bdadc..e24e8f14fe 100644 --- a/examples/bsoncxx/view_and_value.cpp +++ b/examples/bsoncxx/view_and_value.cpp @@ -62,16 +62,16 @@ int main() { // note that all of the interesting methods for reading BSON are defined on the view type. // iterate over the elements in a bson document - for (document::element ele : view) { + for (document::element doc_ele : view) { // element is non owning view of a key-value pair within a document. // we can use the key() method to get a string_view of the key. - stdx::string_view field_key{ele.key()}; + stdx::string_view field_key{doc_ele.key()}; std::cout << "Got key, key = " << field_key << std::endl; // we can use type() to get the type of the value. - switch (ele.type()) { + switch (doc_ele.type()) { case type::k_string: std::cout << "Got String!" << std::endl; break; @@ -81,10 +81,11 @@ int main() { case type::k_array: { std::cout << "Got Array!" << std::endl; // if we have a subarray, we can access it by getting a view of it. - array::view subarr{ele.get_array().value}; - for (array::element ele : subarr) { + array::view subarr{doc_ele.get_array().value}; + for (array::element arr_ele : subarr) { std::cout << "array element: " - << bsoncxx::string::to_string(ele.get_string().value) << std::endl; + << bsoncxx::string::to_string(arr_ele.get_string().value) + << std::endl; } break; } @@ -94,7 +95,7 @@ int main() { // usually we don't need to actually use a switch statement, because we can also // get a variant 'value' that can hold any BSON type. - types::bson_value::view ele_val{ele.get_value()}; + types::bson_value::view doc_ele_val{doc_ele.get_value()}; } // If we want to search for an element we can use operator[] diff --git a/examples/mongocxx/get_values_from_documents.cpp b/examples/mongocxx/get_values_from_documents.cpp index 67c092a918..bf2b0f9587 100644 --- a/examples/mongocxx/get_values_from_documents.cpp +++ b/examples/mongocxx/get_values_from_documents.cpp @@ -63,11 +63,11 @@ void iterate_messagelist(const bsoncxx::document::element& ele) { // Check validity and type before trying to iterate. if (ele.type() == type::k_array) { bsoncxx::array::view subarray{ele.get_array().value}; - for (const bsoncxx::array::element& msg : subarray) { + for (const bsoncxx::array::element& message : subarray) { // Check correct type before trying to access elements. // Only print out fields if they exist; don't report missing fields. - if (msg.type() == type::k_document) { - bsoncxx::document::view subdoc = msg.get_document().value; + if (message.type() == type::k_document) { + bsoncxx::document::view subdoc = message.get_document().value; bsoncxx::document::element uid = subdoc["uid"]; bsoncxx::document::element status = subdoc["status"]; bsoncxx::document::element msg = subdoc["msg"]; diff --git a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/collection.cpp b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/collection.cpp index 8bf91fd293..73a5495500 100644 --- a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/collection.cpp +++ b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/collection.cpp @@ -326,10 +326,10 @@ bsoncxx::v_noabi::builder::basic::document build_find_options_document( } // Prioritize new comment option over old $comment modifier. - if (const auto& comment = options.comment_option()) { - options_builder.append(kvp("comment", *comment)); - } else if (const auto& comment = options.comment()) { - options_builder.append(kvp("comment", *comment)); + if (const auto& new_comment = options.comment_option()) { + options_builder.append(kvp("comment", *new_comment)); + } else if (const auto& old_comment = options.comment()) { + options_builder.append(kvp("comment", *old_comment)); } if (const auto& cursor_type = options.cursor_type()) { diff --git a/src/mongocxx/test/client_side_encryption.cpp b/src/mongocxx/test/client_side_encryption.cpp index 5a55f67078..0eb2d9d324 100644 --- a/src/mongocxx/test/client_side_encryption.cpp +++ b/src/mongocxx/test/client_side_encryption.cpp @@ -2432,11 +2432,11 @@ TEST_CASE("Explicit Encryption", "[client_side_encryption]") { size_t count = 0; for (const auto& it : found) { count++; - auto doc = it.find("encryptedUnindexed")->get_string().value; // Assert one document is returned containing the field { "encryptedUnindexed": // "encrypted unindexed value" }. - REQUIRE(doc == plain_text_unindexed_value); + REQUIRE(it.find("encryptedUnindexed")->get_string().value == + plain_text_unindexed_value); } // Assert one document is returned containing the field { "encryptedUnindexed": @@ -2695,30 +2695,22 @@ TEST_CASE("Unique Index on keyAltNames", "[client_side_encryption]") { // 5. Using client_encryption, create a data key with a local KMS provider and the keyAltName // "def". - mongocxx::options::data_key dk_opts; - dk_opts.key_alt_names({"def"}); - std::string provider = "local"; - auto existing_key = client_encryption.create_data_key(provider, dk_opts); + auto existing_key = client_encryption.create_data_key( + "local", mongocxx::options::data_key().key_alt_names({"def"})); SECTION("Case 1: createKey()") { // 1. Use client_encryption to create a new local data key with a keyAltName "abc" and // assert the operation does not fail. - { - mongocxx::options::data_key dk_opts; - dk_opts.key_alt_names({"abc"}); - std::string provider = "local"; - client_encryption.create_data_key(provider, dk_opts); - } + client_encryption.create_data_key("local", + mongocxx::options::data_key().key_alt_names({"abc"})); // 2. Repeat Step 1 and assert the operation fails due to a duplicate key server error // (error code 11000). { - mongocxx::options::data_key dk_opts; - dk_opts.key_alt_names({"abc"}); - std::string provider = "local"; bool exception_thrown = false; try { - client_encryption.create_data_key(provider, dk_opts); + client_encryption.create_data_key( + "local", mongocxx::options::data_key().key_alt_names({"abc"})); } catch (mongocxx::operation_exception& e) { REQUIRE(std::strstr( e.what(), @@ -2732,12 +2724,10 @@ TEST_CASE("Unique Index on keyAltNames", "[client_side_encryption]") { // 3. Use client_encryption to create a new local data key with a keyAltName "def" and // assert the operation fails due to a duplicate key server error (error code 11000). { - mongocxx::options::data_key dk_opts; - dk_opts.key_alt_names({"def"}); - std::string provider = "local"; bool exception_thrown = false; try { - client_encryption.create_data_key(provider, dk_opts); + client_encryption.create_data_key( + "local", mongocxx::options::data_key().key_alt_names({"def"})); } catch (mongocxx::operation_exception& e) { REQUIRE(std::strstr( e.what(), diff --git a/src/mongocxx/test/database.cpp b/src/mongocxx/test/database.cpp index 5ddb53b538..8f473f5bc1 100644 --- a/src/mongocxx/test/database.cpp +++ b/src/mongocxx/test/database.cpp @@ -180,7 +180,6 @@ TEST_CASE("A database", "[database]") { database_destroy->interpose([&](mongoc_database_t*) { destroy_called = true; }); { - client mongo_client{uri{}, test_util::add_test_server_api()}; database a = mongo_client[database_name]; database b{std::move(a)}; From 311d56bb0fcde842559679eacbab63b29c134e34 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 3 Sep 2024 12:59:35 -0500 Subject: [PATCH 13/16] Improve type consistency of key generation in examples --- .../automatic_client_side_field_level_encryption.cpp | 12 +++++++----- examples/mongocxx/explicit_encryption.cpp | 11 ++++++----- .../mongocxx/explicit_encryption_auto_decryption.cpp | 11 ++++++----- ...erver_side_field_level_encryption_enforcement.cpp | 11 ++++++----- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/examples/mongocxx/automatic_client_side_field_level_encryption.cpp b/examples/mongocxx/automatic_client_side_field_level_encryption.cpp index a47dc397b3..378bfce83f 100644 --- a/examples/mongocxx/automatic_client_side_field_level_encryption.cpp +++ b/examples/mongocxx/automatic_client_side_field_level_encryption.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include #include @@ -101,11 +102,12 @@ int main() { // This must be the same master key that was used to create // the encryption key; here, we use a random key as a placeholder. - char key_storage[kKeyLength]; - std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, - kKeyLength, - reinterpret_cast(&key_storage)}; + std::uint8_t key_storage[kKeyLength]; + std::generate_n(key_storage, kKeyLength, []() { + return static_cast(std::rand() % UINT8_MAX); + }); + bsoncxx::types::b_binary local_master_key{ + bsoncxx::binary_sub_type::k_binary, kKeyLength, key_storage}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/examples/mongocxx/explicit_encryption.cpp b/examples/mongocxx/explicit_encryption.cpp index 022a47f64b..32e4e7414e 100644 --- a/examples/mongocxx/explicit_encryption.cpp +++ b/examples/mongocxx/explicit_encryption.cpp @@ -49,11 +49,12 @@ int main() { // This must be the same master key that was used to create // the encryption key; here, we use a random key as a placeholder. - char key_storage[kKeyLength]; - std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, - kKeyLength, - reinterpret_cast(&key_storage)}; + std::uint8_t key_storage[kKeyLength]; + std::generate_n(key_storage, kKeyLength, []() { + return static_cast(std::rand() % UINT8_MAX); + }); + bsoncxx::types::b_binary local_master_key{ + bsoncxx::binary_sub_type::k_binary, kKeyLength, key_storage}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/examples/mongocxx/explicit_encryption_auto_decryption.cpp b/examples/mongocxx/explicit_encryption_auto_decryption.cpp index 125e7b6115..5f583579c7 100644 --- a/examples/mongocxx/explicit_encryption_auto_decryption.cpp +++ b/examples/mongocxx/explicit_encryption_auto_decryption.cpp @@ -49,11 +49,12 @@ int main() { // This must be the same master key that was used to create // the encryption key; here, we use a random key as a placeholder. - char key_storage[kKeyLength]; - std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, - kKeyLength, - reinterpret_cast(&key_storage)}; + std::uint8_t key_storage[kKeyLength]; + std::generate_n(key_storage, kKeyLength, []() { + return static_cast(std::rand() % UINT8_MAX); + }); + bsoncxx::types::b_binary local_master_key{ + bsoncxx::binary_sub_type::k_binary, kKeyLength, key_storage}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; diff --git a/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp b/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp index 146f48c890..17c1c6ef4c 100644 --- a/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp +++ b/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp @@ -51,11 +51,12 @@ int main() { // This must be the same master key that was used to create // the encryption key; here, we use a random key as a placeholder. - char key_storage[kKeyLength]; - std::generate_n(key_storage, kKeyLength, std::rand); - bsoncxx::types::b_binary local_master_key{bsoncxx::binary_sub_type::k_binary, - kKeyLength, - reinterpret_cast(&key_storage)}; + std::uint8_t key_storage[kKeyLength]; + std::generate_n(key_storage, kKeyLength, []() { + return static_cast(std::rand() % UINT8_MAX); + }); + bsoncxx::types::b_binary local_master_key{ + bsoncxx::binary_sub_type::k_binary, kKeyLength, key_storage}; auto kms_providers = document{} << "local" << open_document << "key" << local_master_key << close_document << finalize; From d768d948043e332724774b0bb73bddb551edb456 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 3 Sep 2024 13:01:17 -0500 Subject: [PATCH 14/16] Address -Wnewline-eof warnings --- examples/mongocxx/tutorial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mongocxx/tutorial.cpp b/examples/mongocxx/tutorial.cpp index d8decb0e09..67582e77e2 100644 --- a/examples/mongocxx/tutorial.cpp +++ b/examples/mongocxx/tutorial.cpp @@ -165,4 +165,4 @@ int main() { // Drop collection to clean up. collection.drop(); -} \ No newline at end of file +} From 4c93a13ac3bba3d0e291edcf01196e550b0dcf74 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 3 Sep 2024 13:03:54 -0500 Subject: [PATCH 15/16] Address -Wswitch-enum via exhaustion instead of internal header inclusion --- examples/bsoncxx/view_and_value.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/bsoncxx/view_and_value.cpp b/examples/bsoncxx/view_and_value.cpp index e24e8f14fe..90e91e4d12 100644 --- a/examples/bsoncxx/view_and_value.cpp +++ b/examples/bsoncxx/view_and_value.cpp @@ -29,10 +29,6 @@ #include #include -#include - -BSONCXX_DISABLE_WARNING(GNU("-Wswitch-enum")); - using namespace bsoncxx; int main() { @@ -89,8 +85,27 @@ int main() { } break; } - default: + + case type::k_double: + case type::k_document: + case type::k_binary: + case type::k_undefined: + case type::k_bool: + case type::k_date: + case type::k_null: + case type::k_regex: + case type::k_dbpointer: + case type::k_code: + case type::k_symbol: + case type::k_codewscope: + case type::k_int32: + case type::k_timestamp: + case type::k_int64: + case type::k_decimal128: + case type::k_maxkey: + case type::k_minkey: std::cout << "We messed up!" << std::endl; + break; } // usually we don't need to actually use a switch statement, because we can also From a3f30a593af94aec97afe976c38cf2c9be069951 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 3 Sep 2024 13:07:53 -0500 Subject: [PATCH 16/16] IWYU + cover more cases of key generation in examples --- examples/mongocxx/explicit_encryption.cpp | 1 + examples/mongocxx/explicit_encryption_auto_decryption.cpp | 1 + .../mongocxx/server_side_field_level_encryption_enforcement.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/mongocxx/explicit_encryption.cpp b/examples/mongocxx/explicit_encryption.cpp index 32e4e7414e..7252ddf520 100644 --- a/examples/mongocxx/explicit_encryption.cpp +++ b/examples/mongocxx/explicit_encryption.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include diff --git a/examples/mongocxx/explicit_encryption_auto_decryption.cpp b/examples/mongocxx/explicit_encryption_auto_decryption.cpp index 5f583579c7..56107fae0d 100644 --- a/examples/mongocxx/explicit_encryption_auto_decryption.cpp +++ b/examples/mongocxx/explicit_encryption_auto_decryption.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include diff --git a/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp b/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp index 17c1c6ef4c..0897c31203 100644 --- a/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp +++ b/examples/mongocxx/server_side_field_level_encryption_enforcement.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include