bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

indent-2.2.11 does not support compound literals


From: Petr Pisar
Subject: indent-2.2.11 does not support compound literals
Date: Wed, 18 Mar 2015 15:13:59 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

Hello,

a user reported <https://bugzilla.redhat.com/show_bug.cgi?id=1199959> that
indent does not support compound literals (see
<http://www.drdobbs.com/the-new-c-compound-literals/184401404>) and that it
can cause indent to print errors and misindent the code.

Input:

#include <stdio.h>

int main(int argc, char **argv)
{
    typedef struct {
        char *capital;
        char *country;
    } t_association;

    t_association a = { "foo", "bar" };
    t_association m;
    m = (t_association){"Paris", "France"};
    m = (t_association){"Rome", "Italy"};
    if (1)
        m = (t_association){"Paris", "France"};
    else
        m = (t_association){"Rome", "Italy"};

    return 0;
}

Output:

$ indent -br < test.c 
#include <stdio.h>

int
main (int argc, char **argv)
{
  typedef struct
  {
    char *capital;
    char *country;
  } t_association;

  t_association a = { "foo", "bar" };
  t_association m;
  m = (t_association) {
  "Paris", "France"};
  m = (t_association) {
  "Rome", "Italy"};
  if (1)
    m = (t_association) {
    "Paris", "France"};
indent: Standard input:16: Error:Unmatched 'else'
  else
  m = (t_association) {
  "Rome", "Italy"};

  return 0;
}

As you can see, the `m = (t_association){"Paris", "France"};' is recgnized as
function call (or just a new statement block) and it's broken at the left
brace.

Then the real if-else lines are thought to be misballanced and an error is
printed.

I believe indent should handle the assignement the same way as the definition
of `a' above. Also please note that a coumpound statement can be used as part
of bigger expression or to be simply void expression. Any idea how to fix it?

-- Petr

Attachment: pgptPFDYR4GSD.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]