diff --git a/include/tlibc/errors.h b/include/tlibc/errors.h index 81b744e..0a26405 100755 --- a/include/tlibc/errors.h +++ b/include/tlibc/errors.h @@ -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) diff --git a/include/tlibc/std.h b/include/tlibc/std.h index 2565afd..ab47485 100755 --- a/include/tlibc/std.h +++ b/include/tlibc/std.h @@ -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.