Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Rewriter bug?

Hi,

I'm working on a refactoring that adds some initializers in the constructor initializers list.
I keep track of the "initializer insert-before locations" for individual class fields; that is either constructor body or next initializer in the field declaration order.

Everything works fine, until there is a comment *before* comma (as a list separator).
E.g., for this code:

struct test {
  X a, b, c;
  test();
};

test() :
  a( /* ... skipped ... */ ),
  // comment after comma
  c( /* ... skipped ... */ )
{}

the ctor initializer list is rewritten correctly into
  a( /* ... skipped ... */ ),
  b( /* ... skipped ... */ ),
  c( /* ... skipped ... */ )

But if the comment is placed before the comma, like here:

test()
  : a( /* ... skipped ... */ )
  // comment before comma
  , c( /* ... skipped ... */ )
{}

the rewritten initializer list is syntactically incorrect:

  : a( /* ... skipped ... */ )
  b( /* ... skipped ... */ ), // comment before comma
  , c( /* ... skipped ... */ )

That is, there no comma between initializers for 'a' and 'b', and two commas between initializers for 'b' and 'c'.

Is there a known work-around for this issue?



Back to the top