Skip to content

Dredd mutates constexpr #233

Closed
Closed
@JamesLee-Jones

Description

Dredd currently mutates constexpr expressions. Since these should be possible to evaluate at compile time, this is not valid unless the Dredd mutation functions are made constexpr accordingly or we avoid mutating them.

The following example demonstrates this error.

#include <iostream>

constexpr int Max(int a, int b) { return a > b ? a : b }

int main() {
  std::cout << Max(5,4) << std::endl;
}

This gives the following error upon compilation:

test.cc:111:15: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
constexpr int Max(int a, int b) { if (!__dredd_enabled_mutation(27)) { return __dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(__dredd_replace_expr_bool_omit_true(__dredd_replace_binary_operator_GT_arg1_int_arg2_int(__dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(a, 0), 2) , __dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(b, 8), 10), 16), 18) ? a : b, 19), 21); } }
              ^
test.cc:111:40: note: non-constexpr function '__dredd_enabled_mutation' cannot be used in a constant expression
constexpr int Max(int a, int b) { if (!__dredd_enabled_mutation(27)) { return __dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(__dredd_replace_expr_bool_omit_true(__dredd_replace_binary_operator_GT_arg1_int_arg2_int(__dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(a, 0), 2) , __dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(b, 8), 10), 16), 18) ? a : b, 19), 21); } }
                                       ^
test.cc:16:13: note: declared here
static bool __dredd_enabled_mutation(int local_mutation_id) {
            ^
1 error generated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions