Skip to content

Commit

Permalink
Merge pull request #2342 from tautschnig/constructor
Browse files Browse the repository at this point in the history
Only parameter-free constructors can be static initializer functions
  • Loading branch information
Daniel Kroening authored Jun 12, 2018
2 parents 12e8f46 + bc568b7 commit 5b8897e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions regression/systemc/Constructor1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct S
{
S(int _x) : x(_x) {}
int x;
};

S s(42);

int main()
{
__CPROVER_assert(s.x == 42, "");
return 0;
}
9 changes: 9 additions & 0 deletions regression/systemc/Constructor1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.cpp

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
no body for function
9 changes: 7 additions & 2 deletions src/linking/static_lifetime_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ bool static_lifetime_init(
{
const symbolt &symbol=ns.lookup(id);

if(symbol.type.id()==ID_code &&
to_code_type(symbol.type).return_type().id()==ID_constructor)
if(symbol.type.id() != ID_code)
continue;

const code_typet &code_type = to_code_type(symbol.type);
if(
code_type.return_type().id() == ID_constructor &&
code_type.parameters().empty())
{
code_function_callt function_call;
function_call.function()=symbol.symbol_expr();
Expand Down

0 comments on commit 5b8897e

Please sign in to comment.