Skip to content

Commit

Permalink
fix Issue 23045 - importC: casted function type is missing extern(C) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed May 1, 2022
1 parent 893c477 commit 84af0a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
sc2.scontinue = null;
sc2.sw = null;
sc2.fes = funcdecl.fes;
sc2.linkage = LINK.d;
sc2.linkage = funcdecl.isCsymbol() ? LINK.c : LINK.d;
sc2.stc &= STC.flowThruFunction;
sc2.visibility = Visibility(Visibility.Kind.public_);
sc2.explicitVisibility = 0;
Expand Down
33 changes: 33 additions & 0 deletions test/runnable/test23045.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* https://issues.dlang.org/show_bug.cgi?id=23045
*/

int printf(const char *s, ...);
void exit(int);

void assert(int b, int line)
{
if (!b)
{
printf("failed test %d\n", line);
exit(1);
}
}

void other(int a, int b)
{
printf("a=%d b=%d\n", a, b);
assert(a == 1, "1");
assert(b == 2, "2");
}

int main()
{
// called like extern(D)
((void (*)(int, int))other)(1, 2);

// Error: incompatible types for `(cast(void function(int, int))& other) is (other)`: `void function(int, int)` and `extern (C) void(int a, int b)`
if (((void (*)(int, int))other) == other)
{ }

return 0;
}

0 comments on commit 84af0a8

Please sign in to comment.