Sitelet https://github.com/phpredis/phpredis/commit/2d963e79
Skip to content

Commit 2d963e7

Browse files
Introduce "must use attribute"
Conditionally add `[[nodiscard]]` (c23) or `__attribute__((warn_unused_result))` when the compiler supports it. This commit initially just adds iit to `cluster_map_keyspace` but we can go throughour API adding it where appropriate.
1 parent 5ebb853 commit 2d963e7

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎cluster_library.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ PHP_REDIS_API redisCluster *cluster_create(double timeout, double read_timeout,
378378
int failover, int persistent);
379379
PHP_REDIS_API void cluster_free(redisCluster *c, int free_ctx);
380380
PHP_REDIS_API void cluster_init_seeds(redisCluster *c, zend_string **seeds, uint32_t nseeds);
381-
PHP_REDIS_API int cluster_map_keyspace(redisCluster *c);
381+
REDIS_NODISCARD PHP_REDIS_API int cluster_map_keyspace(redisCluster *c);
382382
PHP_REDIS_API void cluster_free_node(redisClusterNode *node);
383383

384384
/* Functions for interacting with cached slots maps */

‎common.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@
4141
# error "Unknown endianness"
4242
#endif
4343

44+
#if defined(__has_c_attribute)
45+
# if __has_c_attribute(nodiscard)
46+
# define REDIS_NODISCARD [[nodiscard]]
47+
# endif
48+
#endif
49+
50+
#ifndef REDIS_NODISCARD
51+
# if defined(__has_attribute)
52+
# if __has_attribute(warn_unused_result)
53+
# define REDIS_NODISCARD __attribute__((warn_unused_result))
54+
# endif
55+
# elif defined(__GNUC__) || defined(__clang__)
56+
# define REDIS_NODISCARD __attribute__((warn_unused_result))
57+
# else
58+
# define REDIS_NODISCARD
59+
# endif
60+
#endif
61+
4462
#include "backoff.h"
4563

4664
typedef enum {

0 commit comments

Comments
 (0)