|
| 1 | +/* |
| 2 | + * Copyright 2009-present MongoDB, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
1 | 16 |
|
2 | 17 | #include "common-prelude.h"
|
3 | 18 |
|
|
12 | 27 | #define MONGOC_DEBUG_ASSERT(statement) ((void) 0)
|
13 | 28 | #endif
|
14 | 29 |
|
| 30 | +// `MC_ENABLE_CONVERSION_WARNING_BEGIN` enables -Wconversion to check for potentially unsafe integer conversions. |
| 31 | +// The `bson_in_range_*` functions can help address these warnings by ensuring a cast is within bounds. |
| 32 | +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) // gcc 4.6 added support for "diagnostic push". |
| 33 | +#define MC_ENABLE_CONVERSION_WARNING_BEGIN \ |
| 34 | + _Pragma ("GCC diagnostic push") _Pragma ("GCC diagnostic warning \"-Wconversion\"") |
| 35 | +#define MC_ENABLE_CONVERSION_WARNING_END _Pragma ("GCC diagnostic pop") |
| 36 | +#elif defined(__clang__) |
| 37 | +#define MC_ENABLE_CONVERSION_WARNING_BEGIN \ |
| 38 | + _Pragma ("clang diagnostic push") _Pragma ("clang diagnostic warning \"-Wconversion\"") |
| 39 | +#define MC_ENABLE_CONVERSION_WARNING_END _Pragma ("clang diagnostic pop") |
| 40 | +#else |
| 41 | +#define MC_ENABLE_CONVERSION_WARNING_BEGIN |
| 42 | +#define MC_ENABLE_CONVERSION_WARNING_END |
15 | 43 | #endif
|
| 44 | + |
| 45 | +// Disable the -Wcast-function-type-strict warning. |
| 46 | +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN |
| 47 | +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END |
| 48 | +#if defined(__clang__) |
| 49 | +#if __has_warning("-Wcast-function-type-strict") |
| 50 | +#undef MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN |
| 51 | +#undef MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END |
| 52 | +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN \ |
| 53 | + _Pragma ("clang diagnostic push") _Pragma ("clang diagnostic ignored \"-Wcast-function-type-strict\"") |
| 54 | +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END _Pragma ("clang diagnostic pop") |
| 55 | +#endif // __has_warning("-Wcast-function-type-strict") |
| 56 | +#endif // defined(__clang__) |
| 57 | + |
| 58 | +#endif /* COMMON_MACROS_PRIVATE_H */ |
0 commit comments