added warning on unused Result return value and a way to supress this warning
This commit is contained in:
parent
dbe8924466
commit
ee2b88a412
@ -38,8 +38,13 @@ typedef struct Result_ {
|
||||
};
|
||||
} Result_;
|
||||
|
||||
#define Result(T) Result_
|
||||
|
||||
///Use this macro only to specify function return type.
|
||||
/// To declare variable, use ResultVar().
|
||||
/// Warning can be suppressed by IGNORE_RESULT
|
||||
#define Result(T) Result_ ATTRIBUTE_WARN_UNUSED_RESULT
|
||||
#define ResultVar(T) Result_
|
||||
///USAGE: IGNORE_RESULT trySomething();
|
||||
#define IGNORE_RESULT Result_ __ignored_##__LINE__ ATTRIBUTE_UNUSED =
|
||||
|
||||
#define RESULT_ERROR(MSG, IS_MSG_ON_HEAP) (Result_){ .error = Error_create(MSG, IS_MSG_ON_HEAP, ErrorCallPos_here()) }
|
||||
#define RESULT_ERROR_FMT(FORMAT, ARGS...) RESULT_ERROR(sprintf_malloc(4096, FORMAT ,##ARGS), true)
|
||||
|
||||
@ -73,6 +73,12 @@ typedef const char* cstr;
|
||||
#define ATTRIBUTE_NORETURN \
|
||||
__attribute__ ((__noreturn__))
|
||||
|
||||
#define ATTRIBUTE_WARN_UNUSED_RESULT \
|
||||
__attribute__((warn_unused_result))
|
||||
|
||||
#define ATTRIBUTE_UNUSED \
|
||||
__attribute__ ((unused))
|
||||
|
||||
///@brief https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Common-Function-Attributes.html#index-format-function-attribute
|
||||
///@param FMT_ARG_INDEX Index of format literal argument. First argument is 1.
|
||||
///@param VARIADIC_ARGS_INDEX Index of variadic arguments.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user