traversing structure initializers in c99 style

Hello, cfe-dev!

Suppose i have such statement:

struct data {
  int a;
  int b;
} instance = {
  .b = 10,
  .a = 5,
};

When calling getAnyInitializer() for VarDecl of instance, and
traversing it's children Stmts, it sequentially iterates over the
values, without any mentions of the C99 style used.

Is it possible to detect it and be aware of the order of fields
during initialization?

Thanks!

Hi Vladimir,

The InitListExpr you get from getAnyInitializer() is in
semantic form, which among other things means that designated
initialisers have been eliminated. To get the syntactic form of
the InitListExpr, which includes designated initialisers, you can
call InitListExpr::getSyntacticForm(). See also the comments for
InitListExpr for more information.

Thanks,

Right! That's it, I've missed the InitListExpr part entirely. Thank you.