Thread overview
[Bug 151] New: Pragma without ';' results in undefined symbols
May 23, 2006
d-bugmail
May 24, 2006
d-bugmail
May 24, 2006
Thomas Kuehne
May 24, 2006
Chris Miller
May 30, 2006
Stewart Gordon
May 25, 2006
d-bugmail
May 23, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=151

           Summary: Pragma without ';' results in undefined symbols
           Product: D
           Version: 0.157
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: lio@lunesu.com


>type main.d
import std.stdio;//needs at least 1 import
pragma(lib,"ws2_32.lib")//;
class bla{}
void main(){}

>dmd main.d
C:\dmd\bin\..\..\dm\bin\link.exe main,,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

main.obj(main)
 Error 42: Symbol Undefined __Class_4main3bla
--- errorlevel 1


-- 

May 24, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=151


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com




------- Comment #1 from smjg@iname.com  2006-05-24 09:38 -------
If the semicolon is omitted, then the pragma modifies the declaration or statement that immediately follows it, in this case the class bla.

But it would appear from the spec that pragma(lib) is valid only on its own.
It is indeed absurd that it behaves as it does, but in reality (AIUI) it
shouldn't compile at all.


-- 

May 24, 2006
d-bugmail@puremagic.com schrieb am 2006-05-23:
> http://d.puremagic.com/bugzilla/show_bug.cgi?id=151
>>type main.d
> import std.stdio;//needs at least 1 import
> pragma(lib,"ws2_32.lib")//;
> class bla{}
> void main(){}
>
>>dmd main.d
> C:\dmd\bin\..\..\dm\bin\link.exe main,,,user32+kernel32/noi;
> OPTLINK (R) for Win32  Release 7.50B1
> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
>
> main.obj(main)
>  Error 42: Symbol Undefined __Class_4main3bla
> --- errorlevel 1

While
"pragma(lib, "ws2_32.lib") class Blah{}" [A]
is clearly illegal,
"pragma(lib, "ws2_32.lib") class Blah{};" [B]
is legal but buggy.

http://www.dstress.com/d/pragma.html :
> pragma(ident) declaration; // influence one declaration

Thus [B] should provide the symbols of ws2_32.lib only to the Blah class. I'd opt to state that "lib" and "msg" influence neither declarations nor statements, thus prohibiting:

pragma(msg, "123") statement;
pragma(msg, "123") declaration;
pragma(msg, "123") { statement }
pragma(msg, "123") { declaration }
pragma(msg, "123"): declaration;

pragma(lib, "123") statement;
pragma(lib, "123") declaration;
pragma(lib, "123") { statement }
pragma(lib, "123") { declaration }
pragma(lib, "123"): declaration;

Added to DStress as http://dstress.kuehne.cn/nocompile/p/pragma_07_A.d

Thomas

May 24, 2006
On Wed, 24 May 2006 12:31:15 -0400, Thomas Kuehne <thomas-dloop@kuehne.cn> wrote:

> While
> "pragma(lib, "ws2_32.lib") class Blah{}" [A]
> is clearly illegal,
> "pragma(lib, "ws2_32.lib") class Blah{};" [B]
> is legal but buggy.
>
> http://www.dstress.com/d/pragma.html :
>> pragma(ident) declaration; // influence one declaration
>

Doesn't seem right, notice:

pragma(ident)   // influence block of declarations
{   declaration;
    declaration;
}

doesn't have ";" after the block. Anyway, the way you say wouldn't be consistent with other things, like "extern(C) void foo() {}" doesn't need ";" after. Plus, would that extra ";" have any significance? seems like it would only require extra work in the compiler to enforce. I think "pragma(ident) declaration; // influence one declaration" should not include the ";" and it was only typed in there by habit and/or to look like valid code.
May 25, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=151


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla@digitalmars.com  2006-05-25 04:24 -------
Fixed 0.158


-- 

May 30, 2006
Chris Miller wrote:
> On Wed, 24 May 2006 12:31:15 -0400, Thomas Kuehne <thomas-dloop@kuehne.cn> wrote:
> 
>> While
>> "pragma(lib, "ws2_32.lib") class Blah{}" [A]
>> is clearly illegal,
>> "pragma(lib, "ws2_32.lib") class Blah{};" [B]
>> is legal but buggy.
>> 
>> http://www.dstress.com/d/pragma.html :
>>> pragma(ident) declaration; // influence one declaration
> 
> Doesn't seem right, notice:
> 
> pragma(ident)   // influence block of declarations
> {   declaration;
>     declaration;
> }

Yes, that bit of the spec is rather loose.  It seems it was intended to illustrate, rather than to specify, with the semicolons there merely to make them look like those declarations that happen to end with one.

> doesn't have ";" after the block. Anyway, the way you say wouldn't be consistent with other things, like "extern(C) void foo() {}" doesn't need ";" after. Plus, would that extra ";" have any significance?
<snip>

The syntax for pragmas is incomplete in the spec.  But the trailing ";" in Thomas's snippet is separate from both the class definition and the pragma.  It's a null DeclDef, allowed by the spec only at module level.  It appears that the point is to lighten the load for people coming from C(++), where a semicolon is required after a struct, union, class or enum definition.

Stewart.