-Werror=missing-braces

techtoys
Posts: 26
Joined: Sat Jun 01, 2019 11:11 am

-Werror=missing-braces

Postby techtoys » Sat Jun 01, 2019 11:44 am

Working to port a graphical framework for ESP32-IDF. There is a designer tool under Windows similar to Qt-designer to assemble a GUI with export feature to Eclipse projects. Language in pure C.

In the framework there is a structure like this:

Code: Select all

typedef struct WidgetSlots
{
  union
  {
    void(*Table[3])(void *context);
    struct
    {
      // Pointers to slot functions
      void(*Fcn_A)(void *context); 
      void(*Fcn_B)(void *context); 
      void(*Fcn_C)(void *context); 
    };
  };
} WidgetSlots;
This structure is initialized with code snippet like this:

Code: Select all

static void Widget_Fcn_A(void *context)
{
  //pending
}

static void Widget_Fcn_B(void *context)
{
  //pending
}

static void Widget_Fcn_C(void *context)
{
  //pending
}

void setup() {
  // put your setup code here, to run once:
  static WidgetSlots s_Raised__Slots = {
    (void(*)(void *))Widget_Fcn_A,
    (void(*)(void *))Widget_Fcn_B,
    (void(*)(void *))Widget_Fcn_C,
  };  
}
Unfortunately initialization above doesn't compile in ESP32 IDF. Error is missing braces around initializer [-Werror=missing-braces].

To get around I could add two more brace pairs to pass the IDF compiler. Code as below will compile in IDF.

Code: Select all

  // put your setup code here, to run once:
  static WidgetSlots s_Raised__Slots = {{{
    (void(*)(void *))Widget_Fcn_A,
    (void(*)(void *))Widget_Fcn_B,
    (void(*)(void *))Widget_Fcn_C,
  }}};  
But the problem is that, there are many places in the whole project requires WidgetSlots, and the code is generated by the Windows designer tool. So this is really out of my control to change every single brace pair to triple brace pairs everywhere in the project.

Another peculiar thing is, single brace initialization is working in ESP32 arduino. I am wondering if there is any switch or standard that I can apply to Cross GCC in ESP32 IDF such that initialization with single brace pair works?

Look forward to any suggestion.

John

ESP_Sprite
Posts: 9043
Joined: Thu Nov 26, 2015 4:08 am

Re: -Werror=missing-braces

Postby ESP_Sprite » Sun Jun 02, 2019 1:31 am

The missing braces 'error' actually is a warning (fom GCC to warn you about something that it sees as bad practice) that gets upgraded to an error by ESP-IDF (as we would like to make sure we do not write code like that). You can make gcc ignore it by adding something like '-Wno-error=missing-braces', that downgrades only that specific error back to a warning.

techtoys
Posts: 26
Joined: Sat Jun 01, 2019 11:11 am

Re: -Werror=missing-braces

Postby techtoys » Sun Jun 02, 2019 5:06 am

I tried with CDT Cross GCC Built-in Complier Settings as follows:
xtensa-esp32-elf-gcc ${FLAGS} -std=c++11 -Wno-error=missing-braces -E -P -v -dD "${INPUTS}"

But the same error came up. Wrong place to add -Wno ?

techtoys
Posts: 26
Joined: Sat Jun 01, 2019 11:11 am

Re: -Werror=missing-braces

Postby techtoys » Tue Jun 04, 2019 3:34 am

After few hours of repeat attempt in other places and google search but still I could not locate the correct place to add -Wno-error=missing-braces. Trying to locate under C/C++ Build->Settings->Misc for "Other flags" option but somehow it is missing from ESP32 IDF in Eclipse. In my environment there are only three tabs available as Container Settings, Binary Parsers, and Error Parsers. Any idea how -Wno-error=missing-braces can be added to compiler option?

ESP_Sprite
Posts: 9043
Joined: Thu Nov 26, 2015 4:08 am

Re: -Werror=missing-braces

Postby ESP_Sprite » Tue Jun 04, 2019 10:12 am

I have no idea how your Eclipse setup works, but the normal way would be to add the following in the component.mk of the component containing the generated code:

Code: Select all

CFLAGS+=-Wno-error=missing-braces
CXXFLAGS+=-Wno-error=missing-braces
If you use cmake, the process is a bit different, I can look it up if you need it.

techtoys
Posts: 26
Joined: Sat Jun 01, 2019 11:11 am

Re: -Werror=missing-braces

Postby techtoys » Tue Jun 04, 2019 12:01 pm

Thanks a lot. It is working. I have been focusing too much on Eclipse settings but forgot it is the component.mk file that matters. Switching back to mingw32 with make menuconfig then make flash, the project can be compiled with CFLAGS+=-Wno-=missing-braces in component.mk file. It is only after the project compiled with mingw32 the same project can be compiled in Eclipse.

Thanks again.

Jonathan2892
Posts: 31
Joined: Tue Dec 07, 2021 4:04 pm

Re: -Werror=missing-braces

Postby Jonathan2892 » Fri Mar 03, 2023 10:40 am

ESP_Sprite wrote: If you use cmake, the process is a bit different, I can look it up if you need it.
Hey I am having the same issue, but with VSCode and CMake. I thought I could solve it by adding compile_ooptions to the root CMakeLists.txt:

Code: Select all

# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

add_compile_options(-Wno-error=missing-braces)
add_compile_options(-Wno-unused-variable)


project(esd-integration)

message(STATUS "Building: root")
"-Wno-unused-variable" is working just fine, but "-Wno-error=missing-braces" is not working. Can you give me some guidance to get this working with cmake?

Best


EDIT 1: I just figured out, that it has to be just "Wno-missing-braces" instead of "-Wno-error=missing-braces". Works just fine now.

Who is online

Users browsing this forum: Baidu [Spider] and 138 guests