Thread overview
[Issue 566] New: Adding non-static members and functions to classes doesn't error
Nov 18, 2006
d-bugmail
Jan 29, 2007
d-bugmail
Jan 29, 2007
d-bugmail
[Issue 566] Adding non-static members and functions to classes using a template doesn't error
Apr 19, 2008
d-bugmail
Apr 19, 2008
d-bugmail
Apr 19, 2008
d-bugmail
Jun 29, 2008
d-bugmail
Jul 10, 2008
d-bugmail
November 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=566

           Summary: Adding non-static members and functions to classes
                    doesn't error
           Product: D
           Version: 0.174
          Platform: PC
               URL: http://www.digitalmars.com/d/template.html
        OS/Version: Windows
            Status: NEW
          Keywords: spec
          Severity: normal
          Priority: P4
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: deewiant@gmail.com
OtherBugsDependingO 511
             nThis:


Under the "Limitations" section, the spec states "[t]emplates cannot be used to add non-static members or functions to classes" and showcases the following code:

class Foo
{
    template TBar(T)
    {
        T xx;                   // Error
        int func(T) { ... }     // Error

        static T yy;                            // Ok
        static int func(T t, int y) { ... }     // Ok
    }
}

The lines marked with "// Error" don't fail to compile, they simply behave as though they were declared static. The static attribute on yy and the second func() is thus redundant.

Either the spec or DMD is wrong here.


-- 

January 29, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=566


kamm@incasoftware.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kamm@incasoftware.de




------- Comment #1 from kamm@incasoftware.de  2007-01-29 02:52 -------
*** Bug 878 has been marked as a duplicate of this bug. ***


-- 

January 29, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=566





------- Comment #2 from kamm@incasoftware.de  2007-01-29 03:00 -------
Things seem to have changed a bit: now only the member variable is silently made static while the member function works as a real non-static member template.

class Foo
{
  template TBar(T)
  {
    T x;                   // Compiles, but is implicitly static
    void func(T t)   // Ok, non-static member template function
    { writefln(t); writefln(this.bar); }
  }
  int bar = 42;
}

void main()
{
  Foo.TBar!(int).x = 2;
  Foo.TBar!(int).func(2); // error, since funcx is not static

  Foo f = new Foo;
  Foo g = new Foo;

  f.TBar!(int).func(2); // works

  f.TBar!(int).x = 10;
  g.TBar!(int).x = 20;
  writefln(f.TBar!(int).x); // prints 20
}


-- 

April 19, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=566


kamm-removethis@incasoftware.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dvdfrdmn@users.sf.net




------- Comment #3 from kamm-removethis@incasoftware.de  2008-04-19 14:30 -------
*** Bug 2015 has been marked as a duplicate of this bug. ***


-- 

April 19, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=566





------- Comment #4 from dvdfrdmn@users.sf.net  2008-04-19 16:17 -------
*** Bug 2015 has been marked as a duplicate of this bug. ***


-- 

April 19, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=566





------- Comment #5 from dvdfrdmn@users.sf.net  2008-04-19 16:20 -------
A slightly different test case.  The following compiles, but fails to link.

----
interface TestInterface
  { void tpl(T)(); }
class TestImplementation : TestInterface
  { void tpl(T)() { } }

void main()
{
  /* TestImplementation t = new TestImplementation(); // works */

  TestInterface t = new TestImplementation(); // fails

  t.tpl!(int)();
}
---


-- 

June 29, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=566





------- Comment #6 from bugzilla@digitalmars.com  2008-06-28 19:18 -------
I think the current behavior is useful, but it needs to be documented. The second issue is an error that should be detected by the compiler.


-- 

July 10, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=566


bugzilla@digitalmars.com changed:

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




------- Comment #7 from bugzilla@digitalmars.com  2008-07-09 22:35 -------
Fixed dmd 1.032 and 2.016


--