Skip to content

Commit 5e7232a

Browse files
authored
Reduce Warnings: miscellaneous MSVC warnings (CDRIVER-5981) (#1992)
* Address C4146 "unary minus operator applied to unsigned type" warnings * Address C4189 "local variable is initialized but not referenced" warnings * Address C4210 "nonstandard extension used: function given file scope" warnings * Address C4456 "declaration of 'var' hides previous local declaration" warnings * Address C4308 "negative integral constant converted to unsigned type" warnings * Address C4459 "declaration of 'message_header_length' hides global declaration" warnings * Address C4200 "nonstandard extension used: zero-sized array in struct/union" warnings * Address C4232 "nonstandard extension used: address of dllimport 'foo' is not static" warnings * Address C4100 "unreferenced formal parameter" warnings * Address C4132 "const object should be initialized" warnings * Address C4996 deprecation warnings for mongoc_read_prefs_set_hedge * Address C4702 "unreachable code" warnings * Address C4703 "potentially uninitialized local variable" warnings * Address C2099 "initializer is not a constant" warnings * Address C4100 "unreferenced formal parameter" warnings * Address -Wunused-but-set-variable warnings * Add MLIB_PRAGMA_IF_* macros
1 parent 1b0e008 commit 5e7232a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+340
-199
lines changed

src/common/src/common-b64.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include <bson/bson.h>
4444
#include <common-b64-private.h>
45+
#include <mlib/config.h>
4546
#include <mlib/loop.h>
4647

4748
#define Assert(Cond) \
@@ -270,7 +271,9 @@ static const uint8_t mongoc_b64rmap_invalid = 0xff;
270271
#define mongoc_common_once_t INIT_ONCE
271272
#define MONGOC_COMMON_ONCE_INIT INIT_ONCE_STATIC_INIT
272273
#define mongoc_common_once(o, c) InitOnceExecuteOnce (o, c, NULL, NULL)
273-
#define MONGOC_COMMON_ONCE_FUN(n) BOOL CALLBACK n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c)
274+
#define MONGOC_COMMON_ONCE_FUN(n) \
275+
BOOL CALLBACK MLIB_PRAGMA_IF_MSVC (warning (push)) MLIB_PRAGMA_IF_MSVC (warning (disable : 4100)) \
276+
n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c) MLIB_PRAGMA_IF_MSVC (warning (pop))
274277
#define MONGOC_COMMON_ONCE_RETURN return true
275278
#endif
276279

src/common/src/common-bson-dsl-private.h

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ enum {
3636
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
3737
#endif
3838

39-
#define _bsonDSL_disableWarnings() \
40-
if (1) { \
41-
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic push");) \
42-
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\"");) \
43-
} else \
39+
#define _bsonDSL_disableWarnings() \
40+
if (1) { \
41+
mlib_diagnostic_push (); \
42+
mlib_gnu_warning_disable ("-Wshadow"); \
43+
mlib_msvc_warning (disable : 4456); \
44+
} else \
4445
((void) 0)
4546

46-
#define _bsonDSL_restoreWarnings() \
47-
if (1) { \
48-
BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic pop");) \
49-
} else \
47+
#define _bsonDSL_restoreWarnings() \
48+
if (1) { \
49+
mlib_diagnostic_pop (); \
50+
} else \
5051
((void) 0)
5152

5253
/**
@@ -58,9 +59,12 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
5859
_bsonDSL_begin ("bsonParse(%s)", _bsonDSL_str (Document)); \
5960
_bsonDSL_disableWarnings (); \
6061
bsonParseError = NULL; \
61-
BSON_MAYBE_UNUSED bool _bvHalt = false; \
62-
BSON_MAYBE_UNUSED const bool _bvContinue = false; \
63-
BSON_MAYBE_UNUSED const bool _bvBreak = false; \
62+
bool _bvHalt = false; \
63+
const bool _bvContinue = false; \
64+
const bool _bvBreak = false; \
65+
(void) _bvHalt; \
66+
(void) _bvContinue; \
67+
(void) _bvBreak; \
6468
_bsonDSL_eval (_bsonParse ((Document), __VA_ARGS__)); \
6569
_bsonDSL_restoreWarnings (); \
6670
_bsonDSL_end
@@ -71,7 +75,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
7175
#define bsonVisitEach(Document, ...) \
7276
_bsonDSL_begin ("bsonVisitEach(%s)", _bsonDSL_str (Document)); \
7377
_bsonDSL_disableWarnings (); \
74-
BSON_MAYBE_UNUSED bool _bvHalt = false; \
78+
bool _bvHalt = false; \
79+
(void) _bvHalt; \
7580
_bsonDSL_eval (_bsonVisitEach ((Document), __VA_ARGS__)); \
7681
_bsonDSL_restoreWarnings (); \
7782
_bsonDSL_end
@@ -516,7 +521,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
516521

517522
#define _bsonVisitOperation_case(...) \
518523
_bsonDSL_begin ("case:%s", ""); \
519-
BSON_MAYBE_UNUSED bool _bvCaseMatched = false; \
524+
bool _bvCaseMatched = false; \
525+
(void) _bvCaseMatched; \
520526
_bsonDSL_mapMacro (_bsonVisitCase, ~, __VA_ARGS__); \
521527
_bsonDSL_end
522528

@@ -544,8 +550,10 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
544550
if (!bson_iter_init (&_bvCtx.iter, &(Doc))) { \
545551
bsonParseError = "Invalid BSON data [a]"; \
546552
} \
547-
BSON_MAYBE_UNUSED bool _bvBreak = false; \
548-
BSON_MAYBE_UNUSED bool _bvContinue = false; \
553+
bool _bvBreak = false; \
554+
bool _bvContinue = false; \
555+
(void) _bvBreak; \
556+
(void) _bvContinue; \
549557
while (bson_iter_next (&_bvCtx.iter) && !_bvHalt && !bsonParseError && !_bvBreak) { \
550558
_bvContinue = false; \
551559
_bsonVisit_applyOps (__VA_ARGS__); \
@@ -622,19 +630,23 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
622630
} \
623631
} while (0);
624632

625-
#define _bsonParse(Doc, ...) \
626-
do { \
627-
BSON_MAYBE_UNUSED const bson_t *_bpDoc = &(Doc); \
628-
/* Keep track of which elements have been visited based on their index*/ \
629-
uint64_t _bpVisitBits_static[4] = {0}; \
630-
BSON_MAYBE_UNUSED uint64_t *_bpVisitBits = _bpVisitBits_static; \
631-
BSON_MAYBE_UNUSED size_t _bpNumVisitBitInts = sizeof _bpVisitBits_static / sizeof (uint64_t); \
632-
BSON_MAYBE_UNUSED bool _bpFoundElement = false; \
633-
_bsonParse_applyOps (__VA_ARGS__); \
634-
/* We may have allocated for visit bits */ \
635-
if (_bpVisitBits != _bpVisitBits_static) { \
636-
bson_free (_bpVisitBits); \
637-
} \
633+
#define _bsonParse(Doc, ...) \
634+
do { \
635+
/* Keep track of which elements have been visited based on their index*/ \
636+
uint64_t _bpVisitBits_static[4] = {0}; \
637+
const bson_t *_bpDoc = &(Doc); \
638+
uint64_t *_bpVisitBits = _bpVisitBits_static; \
639+
size_t _bpNumVisitBitInts = sizeof _bpVisitBits_static / sizeof (uint64_t); \
640+
bool _bpFoundElement = false; \
641+
(void) _bpDoc; \
642+
(void) _bpVisitBits; \
643+
(void) _bpNumVisitBitInts; \
644+
(void) _bpFoundElement; \
645+
_bsonParse_applyOps (__VA_ARGS__); \
646+
/* We may have allocated for visit bits */ \
647+
if (_bpVisitBits != _bpVisitBits_static) { \
648+
bson_free (_bpVisitBits); \
649+
} \
638650
} while (0)
639651

640652
#define _bsonParse_applyOps(...) _bsonDSL_mapMacro (_bsonParse_applyOp, ~, __VA_ARGS__)

src/common/src/common-thread-private.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ BSON_BEGIN_DECLS
7979
} while (0)
8080

8181
#else
82+
#include <mlib/config.h>
83+
8284
typedef struct {
8385
pthread_t lock_owner;
8486
pthread_mutex_t wrapped_mutex;
@@ -113,7 +115,9 @@ typedef struct {
113115

114116
#else
115117
#include <process.h>
116-
#define BSON_ONCE_FUN(n) BOOL CALLBACK n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c)
118+
#define BSON_ONCE_FUN(n) \
119+
BOOL CALLBACK MLIB_PRAGMA_IF_MSVC (warning (push)) MLIB_PRAGMA_IF_MSVC (warning (disable : 4100)) \
120+
n (PINIT_ONCE _ignored_a, PVOID _ignored_b, PVOID *_ignored_c) MLIB_PRAGMA_IF_MSVC (warning (pop))
117121
#define BSON_ONCE_INIT INIT_ONCE_STATIC_INIT
118122
#define BSON_ONCE_RETURN return true
119123
#define bson_mutex_destroy DeleteCriticalSection

0 commit comments

Comments
 (0)