Skip to content

Commit 84af0a8

Browse files
WalterBrightdlang-bot
authored andcommitted
fix Issue 23045 - importC: casted function type is missing extern(C) (#14024)
1 parent 893c477 commit 84af0a8

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/dmd/semantic3.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
327327
sc2.scontinue = null;
328328
sc2.sw = null;
329329
sc2.fes = funcdecl.fes;
330-
sc2.linkage = LINK.d;
330+
sc2.linkage = funcdecl.isCsymbol() ? LINK.c : LINK.d;
331331
sc2.stc &= STC.flowThruFunction;
332332
sc2.visibility = Visibility(Visibility.Kind.public_);
333333
sc2.explicitVisibility = 0;

test/runnable/test23045.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* https://issues.dlang.org/show_bug.cgi?id=23045
2+
*/
3+
4+
int printf(const char *s, ...);
5+
void exit(int);
6+
7+
void assert(int b, int line)
8+
{
9+
if (!b)
10+
{
11+
printf("failed test %d\n", line);
12+
exit(1);
13+
}
14+
}
15+
16+
void other(int a, int b)
17+
{
18+
printf("a=%d b=%d\n", a, b);
19+
assert(a == 1, "1");
20+
assert(b == 2, "2");
21+
}
22+
23+
int main()
24+
{
25+
// called like extern(D)
26+
((void (*)(int, int))other)(1, 2);
27+
28+
// Error: incompatible types for `(cast(void function(int, int))& other) is (other)`: `void function(int, int)` and `extern (C) void(int a, int b)`
29+
if (((void (*)(int, int))other) == other)
30+
{ }
31+
32+
return 0;
33+
}

0 commit comments

Comments
 (0)