Bug 4581 – extern function pointers inside functions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-08-04T01:47:41Z
Last change time
2023-10-16T07:07:23Z
Keywords
link-failure, rejects-valid
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2010-08-04T01:47:41Z
import std.c.windows.windows; The following code compiles, but does not link: void main(string[] args) { extern (Windows) HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT); HINSTANCE i = ShellExecuteW(null, "open", "http://www.example.com", null, null, SW_SHOW); } Error 42: Symbol Undefined __D4test4mainFAAyaZi13ShellExecuteWMWT4core3sys7windows7windows6HANDLEPxuPxuPxuPxuiZT4core3sys7windows7windows6HANDLE@24 As we can see, the symbol is D mangled, which it should not be.
Comment #1 by nfxjfg — 2010-08-04T09:05:38Z
It's a feature, not a bug. If the declaration is contained in something nested (like a struct, I guess it also applies to functions), name extern doesn't disable mangling. You can ask Walter for the why. However I didn't find this in the spec and I could be wrong, so I'll leave it to others to find this and mark the bug as invalid.
Comment #2 by simen.kjaras — 2010-08-04T09:20:14Z
I cannot foresee any instance in which it is wanted that the compiler disregard the extern declaration, and even if this is the case, there should at least be a warning as it blithely ignores the programmer's intention.
Comment #3 by dfj1esp02 — 2010-08-04T10:07:30Z
You can't express intention with extern attribute, because it's ambiguous: whether it specifies an external function or internal function with specific calling convention. Currently there's no way to differentiate between these two cases.
Comment #4 by simen.kjaras — 2010-10-26T15:22:51Z
(In reply to comment #3) > You can't express intention with extern attribute, because it's ambiguous: > whether it specifies an external function or internal function with specific > calling convention. Currently there's no way to differentiate between these two > cases. But is there really a difference? Currently, extern( foo ) means 'use foo's calling conventions and name mangling'. As long as the latter is also part of the definition, I do not see such a difference.
Comment #5 by andrej.mitrovich — 2013-01-22T10:36:04Z
Walter can we get your opinion on this?
Comment #6 by b2.temp — 2023-10-16T07:07:23Z
fixed by https://github.com/dlang/dmd/pull/15582. The problem was actually not the extern attribute but the mangle.