Skip to content
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

fix Issue 21970 - importC: Error: variable extern symbols cannot have initializers #12587

Merged
merged 1 commit into from May 27, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/dmd/cparse.d
Expand Up @@ -1541,8 +1541,6 @@ final class CParser(AST) : Parser!AST
hasInitializer = true;
initializer = cparseInitializer();
}
else
initializer = new AST.VoidInitializer(token.loc);
// declare the symbol
assert(id);
if (dt.isTypeFunction())
Expand All @@ -1553,6 +1551,10 @@ final class CParser(AST) : Parser!AST
}
else
{
// Give non-extern variables an implicit void initializer
// if one has not been explicitly set.
if (!hasInitializer && !(specifier.scw & SCW.xextern))
initializer = new AST.VoidInitializer(token.loc);
s = new AST.VarDeclaration(token.loc, dt, id, initializer, specifiersToSTC(level, specifier));
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/compilable/imports/cstuff1.c
Expand Up @@ -345,6 +345,11 @@ union U21963
const int test21967a(void);
const int *test21967b(void);

/********************************/
// https://issues.dlang.org/show_bug.cgi?id=21970
extern int test21970a;
extern char *test21970b;

/********************************/

void test__func__()
Expand Down