Skip to content

Commit 574be89

Browse files
committed
Add error test and fix error message
This commit adds a test of input error and also makes the error message consistent.
1 parent e0fd9f2 commit 574be89

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
enum my_enum
4+
{
5+
first,
6+
second,
7+
third,
8+
fourth,
9+
fifth
10+
};
11+
12+
int main()
13+
{
14+
enum my_enum ev1;
15+
enum my_enum ev2;
16+
ev1 = first;
17+
ev2 = fifth;
18+
assert(__CPROVER_enum_is_in_range(ev1, ev2));
19+
return 0;
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
enum_test12.c
3+
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^file enum_test12.c line \d+ function main: __CPROVER_enum_is_in_range expects 1 argument, 2 were provided$
7+
--
8+
^\[main.assertion.1\] line \d+ assertion __CPROVER_enum_is_in_range\(.*\): SUCCESS$
9+
^\[main.assertion.1\] line \d+ assertion __CPROVER_enum_is_in_range\(.*\): FAILURE$
10+
^\*\*\*\* WARNING: no body for function __CPROVER_enum_is_in_range$
11+
--
12+
This test the type checking of argument for __CPROVER_num_is_in_range

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,7 @@ exprt c_typecheck_baset::do_special_functions(
28472847
if(expr.arguments().size() != 1)
28482848
{
28492849
error().source_location = expr.source_location();
2850-
error() << identifier << " expects one argument, "
2850+
error() << identifier << " expects 1 argument, "
28512851
<< expr.arguments().size() << " were provided" << eom;
28522852
throw 0;
28532853
}
@@ -2866,8 +2866,8 @@ exprt c_typecheck_baset::do_special_functions(
28662866
std::vector<exprt> disjuncts;
28672867
for(const auto &enum_value : enum_values)
28682868
{
2869-
const constant_exprt val{enum_value.get_value(), *c_enum_tag_type};
2870-
disjuncts.push_back(equal_exprt(arg1, val));
2869+
constant_exprt val{enum_value.get_value(), *c_enum_tag_type};
2870+
disjuncts.push_back(equal_exprt(arg1, std::move(val)));
28712871
}
28722872

28732873
return disjunction(disjuncts);

0 commit comments

Comments
 (0)