Skip to content

Commit f9eefa0

Browse files
committed
Fix error output and improve clarity
Fix error output style to follow file exception format. Also improve error messages to be clearer and provide more information.
1 parent 574be89 commit f9eefa0

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

regression/cbmc/enum_is_in_range/enum_test10.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ enum_test10.c
33

44
^EXIT=6$
55
^SIGNAL=0$
6-
^file enum_test10.c line \d+ function main: __CPROVER_enum_is_in_range expects enum argument type$
6+
^file enum_test10.c line \d+ function main: __CPROVER_enum_is_in_range expects enum, but \(i\) has type `signed int`$
77
--
88
^\[main.assertion.1\] line \d+ assertion __CPROVER_enum_is_in_range\(i\): SUCCESS$
99
^\[main.assertion.1\] line \d+ assertion __CPROVER_enum_is_in_range\(i\): FAILURE$

regression/cbmc/enum_is_in_range/enum_test12.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ enum_test12.c
33

44
^EXIT=6$
55
^SIGNAL=0$
6-
^file enum_test12.c line \d+ function main: __CPROVER_enum_is_in_range expects 1 argument, 2 were provided$
6+
^file enum_test12.c line \d+ function main: __CPROVER_enum_is_in_range takes exactly 1 argument, but 2 were provided$
77
--
88
^\[main.assertion.1\] line \d+ assertion __CPROVER_enum_is_in_range\(.*\): SUCCESS$
99
^\[main.assertion.1\] line \d+ assertion __CPROVER_enum_is_in_range\(.*\): FAILURE$

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,10 +2846,11 @@ exprt c_typecheck_baset::do_special_functions(
28462846
// Check correct number of arguments
28472847
if(expr.arguments().size() != 1)
28482848
{
2849-
error().source_location = expr.source_location();
2850-
error() << identifier << " expects 1 argument, "
2851-
<< expr.arguments().size() << " were provided" << eom;
2852-
throw 0;
2849+
std::ostringstream error_message;
2850+
error_message << expr.source_location().as_string() << ": " << identifier
2851+
<< " takes exactly 1 argument, but "
2852+
<< expr.arguments().size() << " were provided";
2853+
throw invalid_source_file_exceptiont{error_message.str()};
28532854
}
28542855
// Replace expr with giant boolean that checks all the values
28552856
// of the enumeration as disjunction
@@ -2875,9 +2876,12 @@ exprt c_typecheck_baset::do_special_functions(
28752876
else
28762877
{
28772878
// Can't enum range check a non-enum
2878-
error().source_location = expr.source_location();
2879-
error() << identifier << " expects enum argument type" << eom;
2880-
throw 0;
2879+
std::ostringstream error_message;
2880+
error_message << expr.source_location().as_string() << ": "
2881+
<< identifier << " expects enum, but ("
2882+
<< expr2c(arg1, *this) << ") has type `"
2883+
<< type2c(arg1.type(), *this) << '`';
2884+
throw invalid_source_file_exceptiont{error_message.str()};
28812885
}
28822886
}
28832887
else if(

0 commit comments

Comments
 (0)