Quick Links: |
Provide support for compiler annotations for compile-time safety. More...
BSLS_ANNOTATION_ALLOC_SIZE(x) | optimize when returning memory |
BSLS_ANNOTATION_ALLOC_SIZE_MUL(x, y) | optimize when returning memory |
BSLS_ANNOTATION_ANALYZER_NORETURN | analyzers treat function as noreturn |
BSLS_ANNOTATION_ERROR("msg") | emit error message and fail compilation |
BSLS_ANNOTATION_WARNING("msg") | emit warning message during compilation |
BSLS_ANNOTATION_PRINTF(s, n) | validate printf format and arguments |
BSLS_ANNOTATION_SCANF(s, n) | validate scanf format and arguments |
BSLS_ANNOTATION_FORMAT(n) | validate printf format in n th argument |
BSLS_ANNOTATION_ARG_NON_NULL(...) | warn if listed arguments are NULL |
BSLS_ANNOTATION_ARGS_NON_NULL | warn if any arguments are NULL |
BSLS_ANNOTATION_NULL_TERMINATED | warn if last argument is non-NULL |
BSLS_ANNOTATION_NULL_TERMINATED_AT(x) | warn if argument at x is non-NULL |
BSLS_ANNOTATION_WARN_UNUSED_RESULT | warn if annotated function result used |
BSLS_ANNOTATION_NODISCARD | warn if annotated function result is not used |
BSLS_ANNOTATION_DEPRECATED | warn if annotated entity is used |
BSLS_ANNOTATION_USED | emit annotated entity even if not referenced |
BSLS_ANNOTATION_UNUSED | do not warn if annotated entity is unused |
BSLS_ANNOTATION_NORETURN | error if function returns normally |
BSLS_ANNOTATION_FALLTHROUGH | do not warn if case fall through |
BSLS_PLATFORM_CMP_GNU
or BSLS_PLATFORM_CMP_CLANG
preprocessor macro is defined. Other compilers may implement a few annotations, but the macros should be expected to work only with compilers for which BSLS_PLATFORM_CMP_GNU
or BSLS_PLATFORM_CMP_CLANG
is defined. __builtin_object_size
with BSLS_PLATFORM_CMP_GNU
or BSLS_PLATFORM_CMP_CLANG
). void *my_calloc(size_t, size_t) BSLS_ANNOTATION_ALLOC_SIZE_MUL(1, 2); void my_realloc(void *, size_t) BSLS_ANNOTATION_ALLOC_SIZE(2);
BSLS_ANNOTATION_ERROR("message") BSLS_ANNOTATION_WARNING("message")
BSLS_ANNOTATION_PRINTF(stringIndex, firstToCheck) BSLS_ANNOTATION_SCANF(stringIndex, firstToCheck)
printf
-style arguments, which should be type-checked against a format string. stringIndex
parameter is the one-based index to the const
format string. The firstToCheck
parameter is the one-based index to the first variable argument to type-check against that format string. For example: extern int my_printf(void *obj, const char *format, ...) BSLS_ANNOTATION_PRINTF(2, 3);
BSLS_ANNOTATION_FORMAT(stringIndex)
printf
-style function and returns a format string that is consistent with that format. This allows format strings manipulated by translation functions to be checked against arguments. Without this annotation, attempting to manipulate the format string via this kind of function might generate warnings about non-literal formats. For example: const char *translateFormat(const char *locale, const char *format) BSLS_ANNOTATION_FORMAT(2);
format
specification passed to translateFormat
. printf(translateFormat("FR", "Name: %s"), "Mike");
BSLS_ANNOTATION_ARG_NON_NULL
annotation is used, it expects a variable list of argument slots to be specified. An argument slot is a one-based index of the argument in the function parameters. The BSLS_ANNOTATION_ARGS_NON_NULL
annotation specifies that all pointer arguments must not be null. NULL
. The annotation is valid only on variadic functions. By default, the sentinel is located at position 0, the last parameter of the function call. If an optional position is specified, the sentinel must be located at that index, counting backwards from the end of the argument list. realloc
function. BSLS_ANNOTATION_NORETURN
might) and should be used in cases where a function cannot be marked [[noreturn]]
but should be treated as such anyway. case
in a switch
statement that is expceted to allow control to fall through instead of ending with a break
, continue
, or return
. This will prevent compilers from warning about fallthrough. int oldFnc() BSLS_ANNOTATION_DEPRECATED; int oldFnc(); int (*fncPtr)() = oldFnc;
void function() BSLS_ANNOTATION_ABC BSLS_ANNOTATION_XYZ;
int foo BSLS_ANNOTATION_ABC BSLS_ANNOTATION_XYZ;