Skip to content

Commit

Permalink
fix Issue 21970 - importC: Error: variable extern symbols cannot have…
Browse files Browse the repository at this point in the history
… initializers
  • Loading branch information
ibuclaw committed May 26, 2021
1 parent 79f0462 commit 899d617
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit 899d617

Please sign in to comment.