[cfe-dev] suggest braces around initialization of subobject confused?

Jack Howarth howarth at bromo.med.uc.edu
Sat May 12 14:55:48 PDT 2012


  I have run into a code fragment from molmol which seems to confuse -Wmissing-braces.
The attached brackets.c produces the warning...

[MacBookPro:~] howarth% /sw/opt/llvm-3.1/bin/clang -Wall -c brackets.c
brackets.c:37:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}},
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {                                                      }
brackets.c:38:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  3, 0, 5, 1, {{D_0, 0}, {D_MZ, 4}, {D_MY, 1}, {D_PX, 2}},
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {                                                      }
brackets.c:39:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  0, 3, 6, 2, {{D_0, 0}, {D_MZ, 3}, {D_PY, 2}, {D_MX, 1}},
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {                                                      }
brackets.c:40:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  3, 5, 6, 7, {{D_0, 0}, {D_PX, 3}, {D_PZ, 1}, {D_PY, 4}},
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {                                                      }
brackets.c:41:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  5, 0, 6, 4, {{D_0, 0}, {D_MY, 3}, {D_MX, 4}, {D_PZ, 2}}
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {                                                      }
brackets.c:37:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}},
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
brackets.c:36:17: warning: unused variable 'CubeEven' [-Wunused-variable]
static CubeDesc CubeEven = {
                ^
7 warnings generated.

However if I follow the hint and add these brackets, clang converts these warnings to...

[MacBookPro:~] howarth% /sw/opt/llvm-3.1/bin/clang -Wall -c brackets2.c
brackets2.c:37:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
 {0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}}},
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {                                                      }
brackets2.c:38:2: warning: excess elements in struct initializer
 {3, 0, 5, 1, {{D_0, 0}, {D_MZ, 4}, {D_MY, 1}, {D_PX, 2}}},
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

For the same code, FSF gcc trunk produces...

[MacBookPro:~] howarth% gcc-fsf-4.8 -Wall -c brackets.c
brackets.c:37:3: warning: missing braces around initializer [-Wmissing-braces]
   0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}},
   ^
brackets.c:37:3: warning: (near initialization for ‘CubeEven.tetA’) [-Wmissing-braces]
   0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}},
   ^
brackets.c:36:17: warning: ‘CubeEven’ defined but not used [-Wunused-variable]
 static CubeDesc CubeEven = {
                 ^
What is the expected compiler behavior here in clang and should I open a PR for this?
Thanks in advance for any advice.
         Jack
-------------- next part --------------
#define TET_NO 5
#define FACE_NO 4
#define EDGE_NO 6

typedef enum {
  D_0,
  D_MX,
  D_PX,
  D_MY,
  D_PY,
  D_MZ,
  D_PZ
} Dir;

typedef struct {
  int selfI;
  int otherI;
} EdgeCorr;

typedef struct {
  Dir dir;
  int ti;
  int pi0, pi1, pi2;
  EdgeCorr corrA[3];
} FaceDesc;

typedef struct {
  int pi0, pi1, pi2, pi3;
  FaceDesc faceA[FACE_NO];
} TetDesc;

typedef struct {
  TetDesc tetA[TET_NO];
} CubeDesc;

static CubeDesc CubeEven = {
  0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}},
  3, 0, 5, 1, {{D_0, 0}, {D_MZ, 4}, {D_MY, 1}, {D_PX, 2}},
  0, 3, 6, 2, {{D_0, 0}, {D_MZ, 3}, {D_PY, 2}, {D_MX, 1}},
  3, 5, 6, 7, {{D_0, 0}, {D_PX, 3}, {D_PZ, 1}, {D_PY, 4}},
  5, 0, 6, 4, {{D_0, 0}, {D_MY, 3}, {D_MX, 4}, {D_PZ, 2}}
};

-------------- next part --------------
#define TET_NO 5
#define FACE_NO 4
#define EDGE_NO 6

typedef enum {
  D_0,
  D_MX,
  D_PX,
  D_MY,
  D_PY,
  D_MZ,
  D_PZ
} Dir;

typedef struct {
  int selfI;
  int otherI;
} EdgeCorr;

typedef struct {
  Dir dir;
  int ti;
  int pi0, pi1, pi2;
  EdgeCorr corrA[3];
} FaceDesc;

typedef struct {
  int pi0, pi1, pi2, pi3;
  FaceDesc faceA[FACE_NO];
} TetDesc;

typedef struct {
  TetDesc tetA[TET_NO];
} CubeDesc;

static CubeDesc CubeEven = {
 {0, 3, 5, 6, {{D_0, 1}, {D_0,  2}, {D_0,  3}, {D_0,  4}}},
 {3, 0, 5, 1, {{D_0, 0}, {D_MZ, 4}, {D_MY, 1}, {D_PX, 2}}},
 {0, 3, 6, 2, {{D_0, 0}, {D_MZ, 3}, {D_PY, 2}, {D_MX, 1}}},
 {3, 5, 6, 7, {{D_0, 0}, {D_PX, 3}, {D_PZ, 1}, {D_PY, 4}}},
 {5, 0, 6, 4, {{D_0, 0}, {D_MY, 3}, {D_MX, 4}, {D_PZ, 2}}}
};



More information about the cfe-dev mailing list