diff --git a/regression/ansi-c/null_pointer_constant1/main.c b/regression/ansi-c/null_pointer_constant1/main.c new file mode 100644 index 00000000000..0497151e052 --- /dev/null +++ b/regression/ansi-c/null_pointer_constant1/main.c @@ -0,0 +1,6 @@ +int main(int argc, char *argv[]) +{ + // Literal 0 is a valid null-pointer constant, which makes this conditional + // operator well-formed. + char *maybe_str = argc > 1 ? "args" : 0; +} diff --git a/regression/ansi-c/null_pointer_constant1/test.desc b/regression/ansi-c/null_pointer_constant1/test.desc new file mode 100644 index 00000000000..466da18b2b5 --- /dev/null +++ b/regression/ansi-c/null_pointer_constant1/test.desc @@ -0,0 +1,8 @@ +CORE +main.c + +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring +^CONVERSION ERROR$ diff --git a/src/ansi-c/c_typecheck_expr.cpp b/src/ansi-c/c_typecheck_expr.cpp index 0ce58dbc2bf..01c2477207b 100644 --- a/src/ansi-c/c_typecheck_expr.cpp +++ b/src/ansi-c/c_typecheck_expr.cpp @@ -1642,6 +1642,18 @@ void c_typecheck_baset::typecheck_expr_trinary(if_exprt &expr) return; } + if( + auto string_constant = expr_try_dynamic_cast(operands[1])) + { + implicit_typecast(operands[1], pointer_type(string_constant->char_type())); + } + + if( + auto string_constant = expr_try_dynamic_cast(operands[2])) + { + implicit_typecast(operands[2], pointer_type(string_constant->char_type())); + } + if(operands[1].type().id()==ID_pointer && operands[2].type().id()!=ID_pointer) implicit_typecast(operands[2], operands[1].type());