Inserting tokens within other tokens?

Issue #11 new
Martin Velez created an issue

In this example, a token ')' (rparen) was inserted between the token '&&' (ampamp) resulting in '&(&' (amp rparen amp).

This breaks my assumption that fixes can be summarized as "Insert TOKEN" and "Delete TOKEN". The sumarry for this case would be "Delete &&. Insert & and ( and &."

&& => &(&
[ampamp] => [amp] [rparen] [amp]

Is this mutation correct?

===Example===
id=46725
name=err_illegal_decl_reference_to_reference
===Section===
type name declared as a reference to a reference
===Section===
---good---
template <typename, typename> struct same_type;
template <typename> struct S;
void f() { same_type<S<int>, int &(&)>; }

===Section===
---bad---
template <typename, typename> struct same_type;
template <typename> struct S;
void f() { same_type<S<int>, int &&)>; }

Comments (5)

  1. Chengnian Sun repo owner

    The original token sequence is "int &(&)", and the mutation is deleting the "(". So in this direction, it is expected.

    However, your repair is a reverse direction, that is, you are inserting a "(" back into a a token. I think the problem is in the formatter. I should format the bad code as "int & &)"

    Do you want to update all the examples?

  2. Martin Velez reporter

    I agree that you should format the code as "int & &)".

    I don't know how many examples are affected by this issue. Perhaps, I can identify and fix them automatically. That way I don't have to reimport. I'll let you know if I can do it.

    Also, I am not sure if you are using a custom formatter. I use clang-format-3.9 with "-style=Chromium" and it seems to do a good job.

    For example:

    marvelez@jarvis:~/sandbox$ cat test.cpp 
    template <typename, typename> struct same_type;
    template <typename> struct S;
    void f() { same_type<S<int>, int &(&)>; }
    template <typename, typename>
    marvelez@jarvis:~/sandbox$ clang-format-3.9 -style=Chromium test.cpp 
    template <typename, typename>
    struct same_type;
    template <typename>
    struct S;
    void f() {
      same_type<S<int>, int&(&)>;
    }
    template <typename, typename>
    
  3. Chengnian Sun repo owner

    The formatting process is more than that. The bad one is usually invalid, and it is not possible for existing formatters to format the bad one.

    1) I first use clang-format to format the good one. 2) Tokenize the good one 3) Generate the bad one based on the good token sequence and the mutation (token deletion, insertion, substitution).

    So, the "&&" is generated by the third step.

  4. Log in to comment