www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5739] New: versioned linkage declarations don't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739

           Summary: versioned linkage declarations don't work
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, rejects-valid, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de



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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739


Jacob Carlborg <doob me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob me.com



In this particular case you could use "extern (System)". But this should
probably be fixed anyway.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739




Yep I know, but the original code is like:

version(CL_VERSION_1_1)
    extern(System):
else
    extern(C):

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID



11:34:16 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739




But how does he get "Error: undefined identifier foo"? Shouldn't "foo" just be
declared as a regular function?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |



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"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739




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();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID



18:57:36 PST ---

 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 20 2012