Skip to content

Commit 318a031

Browse files
authored
Merge pull request #7150 from tautschnig/bugfixes/7135-empty-reason
Function pointer restrictions: fix empty reason in error reporting
2 parents 780490c + d6107b2 commit 318a031

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
3+
int foo()
4+
{
5+
return 10;
6+
}
7+
8+
int bar()
9+
{
10+
return 5;
11+
}
12+
13+
int main()
14+
{
15+
int (*fun_ptr)() = nondet_bool() ? &foo : &bar;
16+
assert(fun_ptr() == 10);
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--restrict-function-pointer fun_ptr.function_pointer_call.1/foo
4+
^Reason: fun_ptr.function_pointer_call.1 not found in the symbol table$
5+
^EXIT=1$
6+
^SIGNAL=0$
7+
--
8+
^Reason:\s*$
9+
--
10+
This test checks that invalid usage results in meaningful error reports.

src/goto-programs/restrict_function_pointers.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ function_pointer_restrictionst function_pointer_restrictionst::from_options(
485485
catch(const invalid_restriction_exceptiont &e)
486486
{
487487
throw invalid_command_line_argument_exceptiont{
488-
e.reason, "--" RESTRICT_FUNCTION_POINTER_OPT, e.correct_format};
488+
static_cast<cprover_exception_baset>(e).what(),
489+
"--" RESTRICT_FUNCTION_POINTER_OPT,
490+
e.correct_format};
489491
}
490492

491493
restrictionst file_restrictions;
@@ -514,7 +516,9 @@ function_pointer_restrictionst function_pointer_restrictionst::from_options(
514516
catch(const invalid_restriction_exceptiont &e)
515517
{
516518
throw invalid_command_line_argument_exceptiont{
517-
e.reason, "--" RESTRICT_FUNCTION_POINTER_BY_NAME_OPT, e.correct_format};
519+
static_cast<cprover_exception_baset>(e).what(),
520+
"--" RESTRICT_FUNCTION_POINTER_BY_NAME_OPT,
521+
e.correct_format};
518522
}
519523

520524
return {merge_function_pointer_restrictions(

src/goto-programs/restrict_function_pointers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class invalid_restriction_exceptiont : public cprover_exception_baset
7979

8080
std::string what() const override;
8181

82-
std::string reason;
8382
std::string correct_format;
8483
};
8584

0 commit comments

Comments
 (0)