From 3531087bb3b2f9ee292d754d326f70468b4ae1ec Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Fri, 2 Aug 2019 15:47:56 +0200 Subject: [PATCH] Revert "str.h: Fix coap_make_str_const() for C++" This reverts commit 2309691770e267b64f7aca39cc8dd6cabf3f499a. As the temporary object is cleaned up, the contents pointed to by the coap_str_const_t object are destroyed. --- include/coap2/str.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/include/coap2/str.h b/include/coap2/str.h index dd89f030..6c1488c9 100644 --- a/include/coap2/str.h +++ b/include/coap2/str.h @@ -91,16 +91,13 @@ void coap_delete_str_const(coap_str_const_t *string); * @param string The const byte array to convert to a coap_str_const_t * */ #ifdef __cplusplus -extern "C++" { -#include -template -coap_str_const_t *coap_make_str_const(T cstr) { - coap_str_const_t s; - s.length = sizeof(cstr)-1; - s.s = reinterpret_cast(cstr); - return std::move(&s); -} +namespace libcoap { + struct CoAPStrConst : coap_str_const_t { + operator coap_str_const_t *() { return this; } + }; } +#define coap_make_str_const(CStr) \ + libcoap::CoAPStrConst{sizeof(CStr)-1, reinterpret_cast(CStr)} #else /* __cplusplus */ #define coap_make_str_const(string) \ (&(coap_str_const_t){sizeof(string)-1,(const uint8_t *)(string)})