www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4430] New: erroneous matching on specialized template function

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

           Summary: erroneous matching on specialized template function
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: s.d.hammett googlemail.com


--- Comment #0 from simon <s.d.hammett googlemail.com> 2010-07-06 02:13:12 PDT
---
A bug has been introduced in 2.037 which in some circumstances causes a
specialized template function to be considered a match even when though it
isn't. 

I tried to cut it down to a small test case but I didn't succeed,
it must be something to do with a specific instantiation which is causing the
bug.

FWIW:

http://www.sstk.co.uk/spiritd.zip

Compiles fine w/ 2.036

If I can make a smaller test case, I'll update this bug report.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 06 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4430


Richard Webb <webby beardmouse.org.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |webby beardmouse.org.uk


--- Comment #1 from Richard Webb <webby beardmouse.org.uk> 2010-07-06 06:25:42
PDT ---
You can repro the compile error in the spiritd test app by doing:

/////////
import spiritd.match, spiritd.nil;

void main(string[] args)
{
    Match!(nilT) temp;
    conv!(Match!(char))(temp);
}
/////////

(you only need the match bits to see the problem, rather than the whole thing).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 06 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4430


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Summary|erroneous matching on       |Regression(2.037) erroneous
                   |specialized template        |matching on specialized
                   |function                    |template function


--- Comment #2 from Don <clugdbug yahoo.com.au> 2010-07-26 11:33:07 PDT ---
Reduced test case:

struct Ghost(T) {}

void bug4430(T)(Ghost!(T) x) {}
void bug4430(T)(Ghost!(int) x)    {}

void spirit4430()
{
    Ghost!(int) temp;
    bug4430!(Ghost!(char))( temp );
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4430



--- Comment #3 from Don <clugdbug yahoo.com.au> 2010-09-01 00:19:06 PDT ---
Even further reduced, shows that a class template is not required.
---
struct Ghost {}

void bug4430(T)(int x)   {}
void bug4430(T)(Ghost x) {}

void spirit4430()
{
    bug4430!(char)( 777 );
}
----
bad.d(53): Error: template instance bug4430!(char) matches more than one
templat
e declaration, bad.d(48):bug4430(T) and bad.d(49):bug4430(T)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4430


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid


--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-09-01 11:57:33 PDT ---
This bug was triggered by svn commit 273, which was related to opDispatch.
The immediate change was in CallExp::semantic(). Previously, it attempted full
explicit instantiation, and if that failed, it tried partial explicit
instantiation. In this case, the full explicit instantiation was failing
(because there were two candidate templates), and then partial instantiation
succeeded. 
After svn 273, it calls needsTypeInference(). If that returns true, it does
partial instantiation, otherwise does full instantiation. In this example, it's
returning false.

There is a situation missing from needsTypeInference(). If there is more than
one candidate template, and they are ALL function templates, and they are ALL 
potentially explicitly instantiated, we need to do partial instantiation.

Template.c, needsTypeInference(), around line 4625.


Index: template.c
===================================================================
--- template.c    (revision 655)
+++ template.c    (working copy)
   -4622,6 +4622,7   
     //printf("TemplateInstance::needsTypeInference() %s\n", toChars());
     if (!tempdecl)
         tempdecl = findTemplateDeclaration(sc);
+    int multipleMatches = FALSE;
     for (TemplateDeclaration *td = tempdecl; td; td = td->overnext)
     {
         /* If any of the overloaded template declarations need inference,
   -4647,9 +4648,14   
         if (Parameter::dim(fdtype->parameters) &&
             (tp || tiargs->dim < td->parameters->dim))
             return TRUE;
+        /* If there is more than one function template which matches, we may
need type inference
+         */
+        if (td != tempdecl)
+            multipleMatches = TRUE;
     }
     //printf("false\n");
-    return FALSE;
+    return multipleMatches;
 }

 void TemplateInstance::semantic2(Scope *sc)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 01 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4430


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2010-09-11
16:47:38 PDT ---
http://www.dsource.org/projects/dmd/changeset/674

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 11 2010