www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7183] New: Bad error message when trying to use this in a static member function of a struct

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

           Summary: Bad error message when trying to use this in a static
                    member function of a struct
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: arsenm2 rpi.edu



Created an attachment (id=1059)
Example of bad + good error

When attempting to use 'this' in a static member function on a struct, the
error message is not helpful.

bad_error_static_this_struct.d(13): Error: need 'this' to access member x

However if the same declaration is made to be 'class' the error is much more
appropriate:

bad_error_static_this_struct.d(25): Error: 'this' is only defined in non-static
member functions, not comparex

Attached is an example.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 29 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7183


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |clugdbug yahoo.com.au
         OS/Version|Linux                       |All



The class error message is generated in the front-end. The struct error message
is generated in the glue layer. Apart from the diagnostic issue, the error
should really be generated in the front-end.

Having it in the glue layer creates problems for CTFE. The following example
errors with "variable x is used before initialization" which is nonsense.

struct BadError
{
    double x = 2.0;
    static int comparex()
    {
        return (this.x <= 3.0);
    }
}

static assert({  BadError z; z.comparex(); return true; }());

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 29 2011