www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5988] New: Error when template is instantiated in a class

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

           Summary: Error when template is instantiated in a class
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: robert octarineparrot.com


--- Comment #0 from Robert Clipsham <robert octarineparrot.com> 2011-05-12
18:43:25 BST ---
The following code:
----
template Templ(alias T)
{
    alias T!int Templ;
}

class C(T) 
{
    Templ!C foo;
}

// Uncomment this to make the error go away
//Templ!C foo;

void main()
{
    C!int a;
}
----
Gives the error:
----
test.d(3): Error: template instance T is not a template declaration, it is a
class
----
When uncommenting the line mentioned in the code the error goes away,
presumably because the forward reference goes away.

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



--- Comment #1 from Robert Clipsham <robert octarineparrot.com> 2011-05-12
20:19:19 BST ---
This issue can be worked around using:
----
alias C Workaround;
class C(T)
{
    Templ!Workaround foo;
}
----
This shouldn't be needed though.

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


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com


--- Comment #2 from kennytm gmail.com 2011-05-12 19:35:48 PDT ---
This is because that class template is actually

    template C(T) {
      class C {
        <declarations>
      }
    }

so the C inside is referring to the class C, not the template C. This code
works:

    class C(T) {
      Templ!(.C) foo;
    }

I don't know why uncomment the global instantiation makes the problem goes
away.

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


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |accepts-invalid
                 CC|                            |andrej.mitrovich gmail.com
         OS/Version|Mac OS X                    |All


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-09
06:06:21 PST ---
(In reply to comment #2)
 This is because that class template is actually
 
     template C(T) {
       class C {
         <declarations>
       }
     }
 
 so the C inside is referring to the class C, not the template C. This code
 works:
 
     class C(T) {
       Templ!(.C) foo;
     }
 
 I don't know why uncomment the global instantiation makes the problem goes
 away.
Yeah, this is an accepts-invalid for this test-case: template Templ(alias T) { alias T!int Templ; } class C(T) { Templ!(C) foo; // should be NG, must use Templ!(.C) } Templ!C foo; void main() { C!int a; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5988



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-09
06:08:43 PST ---
(In reply to comment #3)
 Yeah, this is an accepts-invalid for this test-case:
 
 template Templ(alias T)
 {
     alias T!int Templ;
 }
 
 class C(T)
 {
     Templ!(C) foo;  // should be NG, must use Templ!(.C)
 }
 
 Templ!C foo;
 
 void main()
 {
     C!int a;
 }
I think the cause could perhaps be a mangling issue or the way the compiler searches for template instances. It finds a 'Templ!C' and decides to use that instead of instantiating a new 'Templ!C', where 'C' is something completely different. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5988



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2013-05-18 03:11:11 PDT ---
(In reply to comment #3)
 Yeah, this is an accepts-invalid for this test-case:
 
 template Templ(alias T)
 {
     alias T!int Templ;
 }
 
 class C(T)
 {
     Templ!(C) foo;  // should be NG, must use Templ!(.C)
 }
 
 Templ!C foo;
 
 void main()
 {
     C!int a;
 }
No. This is rejects-valid issue. Templ!(C) would capture class C (not template C), BUT, inside Templ, T!int should be translated to the instantiation of template C. The behavior is consistent with the following: class C(T) { void foo() { C!long c; // here 'C' points class (not template), but C!long will // automatically translated to the template C instantiation. } } C!int c; -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5988


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid             |pull, rejects-valid
           Platform|Other                       |All


--- Comment #6 from Kenji Hara <k.hara.pg gmail.com> 2013-05-18 03:11:54 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2051

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



--- Comment #7 from github-bugzilla puremagic.com 2013-06-25 00:32:39 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d683a052674722d5320a6de44cf2f7456e80b8f7
fix Issue 5988 - Template accepts instantiating an already-instantiated
template type

https://github.com/D-Programming-Language/dmd/commit/771c99c6ccf34032a8cc43f5462caa9e3457630e
Merge pull request #2051 from 9rnsr/fix5988

Issue 5988 - Template accepts instantiating an already-instantiated template
type

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 25 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5988


Walter Bright <bugzilla digitalmars.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 25 2013