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 23045 - importC: casted function type is missing extern(C) #14054

Merged
merged 1 commit into from
May 1, 2022
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
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;
}