mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
fix Issue 22755 - ImportC: declared symbol must be available in initializer
This commit is contained in:
parent
05a27e287e
commit
d96d66a560
2 changed files with 31 additions and 12 deletions
|
@ -5248,21 +5248,21 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
VarDeclaration v = s.isVarDeclaration();
|
|
||||||
if (v)
|
|
||||||
{
|
|
||||||
// Do semantic() on initializer first, so:
|
|
||||||
// int a = a;
|
|
||||||
// will be illegal.
|
|
||||||
e.declaration.dsymbolSemantic(sc);
|
|
||||||
s.parent = sc.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
//printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
|
//printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
|
||||||
// Insert into both local scope and function scope.
|
// Insert into both local scope and function scope.
|
||||||
// Must be unique in both.
|
// Must be unique in both.
|
||||||
if (s.ident)
|
if (s.ident)
|
||||||
{
|
{
|
||||||
|
VarDeclaration v = s.isVarDeclaration();
|
||||||
|
if (v && !(sc.flags & SCOPE.Cfile))
|
||||||
|
{
|
||||||
|
/* Do semantic() on initializer first so this will be illegal:
|
||||||
|
* int a = a;
|
||||||
|
*/
|
||||||
|
e.declaration.dsymbolSemantic(sc);
|
||||||
|
s.parent = sc.parent;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sc.insert(s))
|
if (!sc.insert(s))
|
||||||
{
|
{
|
||||||
auto conflict = sc.search(Loc.initial, s.ident, null);
|
auto conflict = sc.search(Loc.initial, s.ident, null);
|
||||||
|
@ -5271,7 +5271,17 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
|
||||||
conflict.kind(), conflict.toChars());
|
conflict.kind(), conflict.toChars());
|
||||||
return setError();
|
return setError();
|
||||||
}
|
}
|
||||||
else if (sc.func)
|
|
||||||
|
if (v && (sc.flags & SCOPE.Cfile))
|
||||||
|
{
|
||||||
|
/* Do semantic() on initializer last so this will be legal:
|
||||||
|
* int a = a;
|
||||||
|
*/
|
||||||
|
e.declaration.dsymbolSemantic(sc);
|
||||||
|
s.parent = sc.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sc.func)
|
||||||
{
|
{
|
||||||
// https://issues.dlang.org/show_bug.cgi?id=11720
|
// https://issues.dlang.org/show_bug.cgi?id=11720
|
||||||
if ((s.isFuncDeclaration() ||
|
if ((s.isFuncDeclaration() ||
|
||||||
|
@ -5299,7 +5309,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
|
||||||
|
|
||||||
// The mangling change only works for D mangling
|
// The mangling change only works for D mangling
|
||||||
}
|
}
|
||||||
// else
|
|
||||||
{
|
{
|
||||||
/* https://issues.dlang.org/show_bug.cgi?id=21272
|
/* https://issues.dlang.org/show_bug.cgi?id=21272
|
||||||
* If we are in a foreach body we need to extract the
|
* If we are in a foreach body we need to extract the
|
||||||
|
|
9
test/compilable/test22755.c
Normal file
9
test/compilable/test22755.c
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// issues.dlang.org/show_bug.cgi?id=22755
|
||||||
|
|
||||||
|
void *malloc(unsigned);
|
||||||
|
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
int *p = malloc(sizeof *p);
|
||||||
|
int x = x;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue