mc-imperial / dredd

Framework for evaluating C/C++ compiler testing tools
Apache License 2.0
11 stars 3 forks source link

Dredd mutate the constant int used in aggregate initialisation #265

Closed JonathanFoo0523 closed 1 month ago

JonathanFoo0523 commented 1 month ago

Dredd mutates the the sole statement in main() in the following file:

class a {
public:
  a(int) {}
};
int main() { 
    new a[2]{4, 5}; 
}

to

if (!__dredd_enabled_mutation(13)) { new a[__dredd_replace_expr_unsigned_long_constant(2, 0)]{__dredd_replace_expr_int_constant(4, 3), __dredd_replace_expr_int_constant(5, 8)}; }

This results in compilation error:

error: no matching constructor for initialization of 'a'
note: candidate constructor not viable: requires 1 argument, but 0 were provided
JonathanFoo0523 commented 1 month ago

I believe this problem occurs because C++ doesn't allow the use of a non-constant array size for list initialization of a type that doesn't have a zero-argument constructor. If we modify class a to become:

class a {
public:
  a(int) {}
  a() {}
};

then the dredd-mutated program will compile.

I think checking whether a type used for list initialization has a zero-argument constructor is non-trivial, so I will avoid mutating the array size regardless of the type.