mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 07:37:29 +00:00
lib: add macro that performs explicit static casts when using a C++ compiler
C++ doesn't support implicit casts from void pointers like C does. And the libfrr headers have some bits of code that rely on implicit casts in order to work. To solve this problem, add a new "static_cast" macro that performs explicit static casts when a C++ compiler is being used, or do nothing otherwise. NOTE: since macros are only evaluated when they are used, there might be other macros from libfrr that will need to use "static_cast" as well. If a header is successfully compiled using a C++ compiler, there's no guarantee that its macros are compatible with C++. We'll only know about such macros when they are used by C++ code, then we'll need to adapt them one by one in the future. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
c139972c0f
commit
343cd13e17
@ -295,7 +295,8 @@ extern void list_add_list(struct list *list, struct list *add);
|
|||||||
#define ALL_LIST_ELEMENTS(list, node, nextnode, data) \
|
#define ALL_LIST_ELEMENTS(list, node, nextnode, data) \
|
||||||
(node) = listhead(list), ((data) = NULL); \
|
(node) = listhead(list), ((data) = NULL); \
|
||||||
(node) != NULL \
|
(node) != NULL \
|
||||||
&& ((data) = listgetdata(node), (nextnode) = node->next, 1); \
|
&& ((data) = static_cast(data, listgetdata(node)), \
|
||||||
|
(nextnode) = node->next, 1); \
|
||||||
(node) = (nextnode), ((data) = NULL)
|
(node) = (nextnode), ((data) = NULL)
|
||||||
|
|
||||||
/* read-only list iteration macro.
|
/* read-only list iteration macro.
|
||||||
@ -306,7 +307,7 @@ extern void list_add_list(struct list *list, struct list *add);
|
|||||||
*/
|
*/
|
||||||
#define ALL_LIST_ELEMENTS_RO(list, node, data) \
|
#define ALL_LIST_ELEMENTS_RO(list, node, data) \
|
||||||
(node) = listhead(list), ((data) = NULL); \
|
(node) = listhead(list), ((data) = NULL); \
|
||||||
(node) != NULL && ((data) = listgetdata(node), 1); \
|
(node) != NULL && ((data) = static_cast(data, listgetdata(node)), 1); \
|
||||||
(node) = listnextnode(node), ((data) = NULL)
|
(node) = listnextnode(node), ((data) = NULL)
|
||||||
|
|
||||||
/* these *do not* cleanup list nodes and referenced data, as the functions
|
/* these *do not* cleanup list nodes and referenced data, as the functions
|
||||||
|
@ -232,6 +232,15 @@ typedef unsigned char uint8_t;
|
|||||||
|
|
||||||
#include "zassert.h"
|
#include "zassert.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add explicit static cast only when using a C++ compiler.
|
||||||
|
*/
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define static_cast(l, r) static_cast<decltype(l)>((r))
|
||||||
|
#else
|
||||||
|
#define static_cast(l, r) (r)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_STRLCAT
|
#ifndef HAVE_STRLCAT
|
||||||
size_t strlcat(char *__restrict dest,
|
size_t strlcat(char *__restrict dest,
|
||||||
const char *__restrict src, size_t destsize);
|
const char *__restrict src, size_t destsize);
|
||||||
|
Loading…
Reference in New Issue
Block a user