Skip to content

BUG at last commit “Make struct member access to work with = and ?: #165

@zhzhz

Description

@zhzhz
#include "test.h"

int main()
{
  ASSERT(2, ({ struct { int a,b; } x[]={[1].a=1,2,[0]=3,4,}; x[1].b; }));

  printf("OK\n");
  return 0;
}

To compile code above,chibicc will report “expected an expression”.

I fix it in function "struct_initializer2",see fix here comment

static void struct_initializer2(Token **rest, Token *tok, Initializer *init, Member *mem)
{
  bool first = true;

  for (; mem && !is_end(tok); mem = mem->next)
  {
    Token *start = tok;

    if (!first)
      tok = skip(tok, ",");

    //fix here
    if (first && equal(tok, ","))
    {
      tok = skip(tok, ",");
    }
    //fix here

    first = false;

    if (equal(tok, "[") || equal(tok, "."))
    {
      *rest = start;
      return;
    }

    initializer2(&tok, tok, init->children[mem->idx]);
  }
  *rest = tok;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions