Skip to content

Constructor attribute is not required with forward declaration #7594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion regression/cbmc/constructor1/main.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
#include <assert.h>

#ifdef __GNUC__
int x;
int x, y;

// forward declaration with and without attribute is ok
static __attribute__((constructor)) void format_init(void);
static void other_init(void);

static __attribute__((constructor))
void format_init(void)
{
x=42;
return;
}

static __attribute__((constructor)) void other_init(void)
{
y = 42;
}
#endif

int main()
{
#ifdef __GNUC__
assert(x==42);
assert(y == 42);
#endif
return 0;
}
4 changes: 3 additions & 1 deletion src/ansi-c/c_typecheck_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ void c_typecheck_baset::typecheck_redefinition_non_type(

if(
old_ct.return_type() != new_ct.return_type() &&
!old_ct.get_bool(ID_C_incomplete))
!old_ct.get_bool(ID_C_incomplete) &&
new_ct.return_type().id() != ID_constructor &&
new_ct.return_type().id() != ID_destructor)
{
throw invalid_source_file_exceptiont{
"function symbol '" + id2string(new_symbol.display_name()) +
Expand Down