Skip to content

Commit 2f2026e

Browse files
adamgreenadbridge
authored andcommitted
Fix C++11 build error w/ u-blox EVK-ODIN-W2
When attempting to perform a test build of various mbed-os targets with GCC configured to build -std=gnu++11, all of the targets built successfully except for this one. It gave errors like this: ../mbed-os/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/wifi_emac/wifi_emac_api.cpp: In function 'emac_interface_t* wifi_emac_get_interface()': ../mbed-os/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/wifi_emac/wifi_emac_api.cpp:331:38: error: use of deleted function 'emac_interface::emac_interface()' _intf = new emac_interface_t(); ^ In file included from ../mbed-os/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/wifi_emac/wifi_emac_api.cpp:9:0: ../mbed-os/hal/emac_api.h:150:16: note: 'emac_interface::emac_interface()' is implicitly deleted because the default definition would be ill-formed: typedef struct emac_interface { ^ ../mbed-os/hal/emac_api.h:150:16: error: uninitialized const member in 'struct emac_interface' ../mbed-os/hal/emac_api.h:151:32: note: 'const emac_interface_ops_t emac_interface::ops' should be initialized const emac_interface_ops_t ops; This commit contains a proposed change which fixes this issue by not using the new operator to allocate the emac_interface_t structure but instead using the malloc() function since the construction is being handled explicitly in the subsequent lines of the wifi_emac_get_interface() function anyway. I also added code which only completes the initialization of the _intf object if its allocation succeeds and just returns NULL otherwise. I see no deallocation of the _intf object occurring so no change from delete to free() needed to be made.
1 parent 5ab3fb8 commit 2f2026e

File tree

1 file changed

+5
-3
lines changed
  • targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/wifi_emac

1 file changed

+5
-3
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/wifi_emac/wifi_emac_api.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ static void wifi_set_link_state_cb(emac_interface_t *emac, emac_link_state_chang
328328
emac_interface_t* wifi_emac_get_interface()
329329
{
330330
if (_intf == NULL) {
331-
_intf = new emac_interface_t();
332-
_intf->hw = NULL;
333-
memcpy((void*)&_intf->ops, &wifi_emac_interface, sizeof(wifi_emac_interface));
331+
_intf = (emac_interface_t*)malloc(sizeof(emac_interface_t));
332+
if (_intf) {
333+
_intf->hw = NULL;
334+
memcpy((void*)&_intf->ops, &wifi_emac_interface, sizeof(wifi_emac_interface));
335+
}
334336
}
335337
return _intf;
336338
}

0 commit comments

Comments
 (0)