Skip to content

Reduce Warnings: miscellaneous MSVC warnings (CDRIVER-5981) #1992

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
d1a2940
Address C4146 "unary minus operator applied to unsigned type" warnings
eramongodb Apr 11, 2025
5e68c25
Address C4189 "local variable is initialized but not referenced" warn…
eramongodb Apr 11, 2025
564cea8
Address C4210 "nonstandard extension used: function given file scope"…
eramongodb Apr 11, 2025
d595ea6
Address C4456 "declaration of 'var' hides previous local declaration"…
eramongodb Apr 11, 2025
8fdba64
Address C4308 "negative integral constant converted to unsigned type"…
eramongodb Apr 11, 2025
6809b03
Address C4459 "declaration of 'message_header_length' hides global de…
eramongodb Apr 11, 2025
b3dc106
Address C4200 "nonstandard extension used: zero-sized array in struct…
eramongodb Apr 11, 2025
34ad814
Address C4232 "nonstandard extension used: address of dllimport 'foo'…
eramongodb Apr 11, 2025
ba757b9
Address C4100 "unreferenced formal parameter" warnings
eramongodb Apr 11, 2025
077e815
Address C4132 "const object should be initialized" warnings
eramongodb Apr 11, 2025
a2703b3
Address C4996 deprecation warnings for mongoc_read_prefs_set_hedge
eramongodb Apr 11, 2025
ae5ce01
Address C4702 "unreachable code" warnings
eramongodb Apr 11, 2025
7d8d061
Address C4703 "potentially uninitialized local variable" warnings
eramongodb Apr 11, 2025
1978003
Address C2099 "initializer is not a constant" warnings
eramongodb Apr 11, 2025
00d5b4d
Fix VS 2015 syntax errors due to pragma position
eramongodb Apr 11, 2025
25ad7c6
Merge remote-tracking branch 'upstream/master' into cdriver-warnings
eramongodb Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/common/src/common-b64.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <bson/bson.h>
#include <common-b64-private.h>
#include <mlib/config.h>
#include <mlib/loop.h>

#define Assert(Cond) \
Expand Down Expand Up @@ -270,7 +271,9 @@ static const uint8_t mongoc_b64rmap_invalid = 0xff;
#define mongoc_common_once_t INIT_ONCE
#define MONGOC_COMMON_ONCE_INIT INIT_ONCE_STATIC_INIT
#define mongoc_common_once(o, c) InitOnceExecuteOnce (o, c, NULL, NULL)
#define MONGOC_COMMON_ONCE_FUN(n) BOOL CALLBACK n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c)
#define MONGOC_COMMON_ONCE_FUN(n) \
BOOL CALLBACK MLIB_IF_MSVC (__pragma (warning (push)) __pragma (warning (disable : 4100))) \
n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c) MLIB_IF_MSVC (__pragma (warning (pop)))
#define MONGOC_COMMON_ONCE_RETURN return true
#endif

Expand Down
70 changes: 41 additions & 29 deletions src/common/src/common-bson-dsl-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ enum {
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
#endif

#define _bsonDSL_disableWarnings() \
if (1) { \
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic push");) \
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\"");) \
} else \
#define _bsonDSL_disableWarnings() \
if (1) { \
mlib_diagnostic_push (); \
mlib_gnu_warning_disable ("-Wshadow"); \
mlib_msvc_warning (disable : 4456); \
} else \
((void) 0)

#define _bsonDSL_restoreWarnings() \
if (1) { \
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic pop");) \
} else \
#define _bsonDSL_restoreWarnings() \
if (1) { \
mlib_diagnostic_pop (); \
} else \
((void) 0)

/**
Expand All @@ -58,9 +59,12 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
_bsonDSL_begin ("bsonParse(%s)", _bsonDSL_str (Document)); \
_bsonDSL_disableWarnings (); \
bsonParseError = NULL; \
BSON_MAYBE_UNUSED bool _bvHalt = false; \
BSON_MAYBE_UNUSED const bool _bvContinue = false; \
BSON_MAYBE_UNUSED const bool _bvBreak = false; \
bool _bvHalt = false; \
const bool _bvContinue = false; \
const bool _bvBreak = false; \
(void) _bvHalt; \
(void) _bvContinue; \
(void) _bvBreak; \
_bsonDSL_eval (_bsonParse ((Document), __VA_ARGS__)); \
_bsonDSL_restoreWarnings (); \
_bsonDSL_end
Expand All @@ -71,7 +75,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
#define bsonVisitEach(Document, ...) \
_bsonDSL_begin ("bsonVisitEach(%s)", _bsonDSL_str (Document)); \
_bsonDSL_disableWarnings (); \
BSON_MAYBE_UNUSED bool _bvHalt = false; \
bool _bvHalt = false; \
(void) _bvHalt; \
_bsonDSL_eval (_bsonVisitEach ((Document), __VA_ARGS__)); \
_bsonDSL_restoreWarnings (); \
_bsonDSL_end
Expand Down Expand Up @@ -516,7 +521,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))

#define _bsonVisitOperation_case(...) \
_bsonDSL_begin ("case:%s", ""); \
BSON_MAYBE_UNUSED bool _bvCaseMatched = false; \
bool _bvCaseMatched = false; \
(void) _bvCaseMatched; \
_bsonDSL_mapMacro (_bsonVisitCase, ~, __VA_ARGS__); \
_bsonDSL_end

Expand Down Expand Up @@ -544,8 +550,10 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
if (!bson_iter_init (&_bvCtx.iter, &(Doc))) { \
bsonParseError = "Invalid BSON data [a]"; \
} \
BSON_MAYBE_UNUSED bool _bvBreak = false; \
BSON_MAYBE_UNUSED bool _bvContinue = false; \
bool _bvBreak = false; \
bool _bvContinue = false; \
(void) _bvBreak; \
(void) _bvContinue; \
while (bson_iter_next (&_bvCtx.iter) && !_bvHalt && !bsonParseError && !_bvBreak) { \
_bvContinue = false; \
_bsonVisit_applyOps (__VA_ARGS__); \
Expand Down Expand Up @@ -622,19 +630,23 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
} \
} while (0);

#define _bsonParse(Doc, ...) \
do { \
BSON_MAYBE_UNUSED const bson_t *_bpDoc = &(Doc); \
/* Keep track of which elements have been visited based on their index*/ \
uint64_t _bpVisitBits_static[4] = {0}; \
BSON_MAYBE_UNUSED uint64_t *_bpVisitBits = _bpVisitBits_static; \
BSON_MAYBE_UNUSED size_t _bpNumVisitBitInts = sizeof _bpVisitBits_static / sizeof (uint64_t); \
BSON_MAYBE_UNUSED bool _bpFoundElement = false; \
_bsonParse_applyOps (__VA_ARGS__); \
/* We may have allocated for visit bits */ \
if (_bpVisitBits != _bpVisitBits_static) { \
bson_free (_bpVisitBits); \
} \
#define _bsonParse(Doc, ...) \
do { \
/* Keep track of which elements have been visited based on their index*/ \
uint64_t _bpVisitBits_static[4] = {0}; \
const bson_t *_bpDoc = &(Doc); \
uint64_t *_bpVisitBits = _bpVisitBits_static; \
size_t _bpNumVisitBitInts = sizeof _bpVisitBits_static / sizeof (uint64_t); \
bool _bpFoundElement = false; \
(void) _bpDoc; \
(void) _bpVisitBits; \
(void) _bpNumVisitBitInts; \
(void) _bpFoundElement; \
_bsonParse_applyOps (__VA_ARGS__); \
/* We may have allocated for visit bits */ \
if (_bpVisitBits != _bpVisitBits_static) { \
bson_free (_bpVisitBits); \
} \
} while (0)

#define _bsonParse_applyOps(...) _bsonDSL_mapMacro (_bsonParse_applyOp, ~, __VA_ARGS__)
Expand Down
6 changes: 5 additions & 1 deletion src/common/src/common-thread-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ BSON_BEGIN_DECLS
} while (0)

#else
#include <mlib/config.h>

typedef struct {
pthread_t lock_owner;
pthread_mutex_t wrapped_mutex;
Expand Down Expand Up @@ -113,7 +115,9 @@ typedef struct {

#else
#include <process.h>
#define BSON_ONCE_FUN(n) BOOL CALLBACK n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c)
#define BSON_ONCE_FUN(n) \
BOOL CALLBACK MLIB_IF_MSVC (__pragma (warning (push)) __pragma (warning (disable : 4100))) \
n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c) MLIB_IF_MSVC (__pragma (warning (pop)))
#define BSON_ONCE_INIT INIT_ONCE_STATIC_INIT
#define BSON_ONCE_RETURN return true
#define bson_mutex_destroy DeleteCriticalSection
Expand Down
Loading