Bug 5739 – versioned linkage declarations don't work

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-15T04:51:00Z
Last change time
2015-06-09T05:11:37Z
Keywords
accepts-invalid, rejects-valid, wrong-code
Assigned to
nobody
Creator
hoganmeier

Comments

Comment #0 by hoganmeier — 2011-03-15T04:51:51Z
main.d: ======= import versionextern; void main() { foo(); } versionextern.d: ================ version = Bla; version(Bla) { extern(Windows): } else version(Blub) { extern(C): } void foo(); yields: Symbol Undefined _D13versionextern3fooFZv no matter what version is defined. removing the parentheses and else: version(Bla) extern(Windows): version(Blub) extern(C): even results in: main(5): Error: undefined identifier foo I'm not sure if this is a rejects-valid or accepts-invalid issue.
Comment #1 by doob — 2011-03-15T05:47:14Z
In this particular case you could use "extern (System)". But this should probably be fixed anyway.
Comment #2 by hoganmeier — 2011-03-15T10:06:21Z
Yep I know, but the original code is like: version(CL_VERSION_1_1) extern(System): else extern(C):
Comment #3 by bugzilla — 2011-03-15T11:34:16Z
This is not a bug. A linkage declaration that ends in ':' runs to the end of the block, which in this case is the end of the version declaration.
Comment #4 by doob — 2011-03-15T12:30:42Z
But how does he get "Error: undefined identifier foo"? Shouldn't "foo" just be declared as a regular function?
Comment #5 by hoganmeier — 2011-03-18T02:45:55Z
Yep, the second issue still persists. I found out what I originally wanted to do can be achieved via: extern(C): version(Bla) extern(Windows): // though replacing this with mixin("extern(Windows):"); doesn't work, then extern(C) wins void foo(); But as soon as you have 2 blocks like version(Bla) extern(Windows): version(Blub) extern(C++): and Blub isn't set, it fails with "undefined identifier foo"
Comment #6 by hoganmeier — 2011-03-18T02:57:13Z
Ah never mind, turns out it doesn't work. extern(C): version(Bla) extern(Windows): void foo(); fails as soon as Bla isn't defined. I guess it has to do with the parser. Because of the ':' it probably gets read like: version(Bla) { extern(Windows): void foo(); }
Comment #7 by bugzilla — 2012-01-20T18:57:36Z
(In reply to comment #4) > But how does he get "Error: undefined identifier foo"? Shouldn't "foo" just be > declared as a regular function? It gets parsed like: extern(C): void foo(); and so foo is undefined.