Closed
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