Skip to content

Commit cf084e6

Browse files
authored
Merge pull request #7594 from tautschnig/bugfixes/constructor
Constructor attribute is not required with forward declaration
2 parents 3cf1ade + 7c41e4d commit cf084e6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

regression/cbmc/constructor1/main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
#include <assert.h>
22

33
#ifdef __GNUC__
4-
int x;
4+
int x, y;
55

6+
// forward declaration with and without attribute is ok
67
static __attribute__((constructor)) void format_init(void);
8+
static void other_init(void);
79

810
static __attribute__((constructor))
911
void format_init(void)
1012
{
1113
x=42;
1214
return;
1315
}
16+
17+
static __attribute__((constructor)) void other_init(void)
18+
{
19+
y = 42;
20+
}
1421
#endif
1522

1623
int main()
1724
{
1825
#ifdef __GNUC__
1926
assert(x==42);
27+
assert(y == 42);
2028
#endif
2129
return 0;
2230
}

src/ansi-c/c_typecheck_base.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
375375

376376
if(
377377
old_ct.return_type() != new_ct.return_type() &&
378-
!old_ct.get_bool(ID_C_incomplete))
378+
!old_ct.get_bool(ID_C_incomplete) &&
379+
new_ct.return_type().id() != ID_constructor &&
380+
new_ct.return_type().id() != ID_destructor)
379381
{
380382
throw invalid_source_file_exceptiont{
381383
"function symbol '" + id2string(new_symbol.display_name()) +

0 commit comments

Comments
 (0)