www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 38] New: Template crashes DMD

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

           Summary: Template crashes DMD
           Product: D
           Version: 0.149
          Platform: Macintosh
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: braddr puremagic.com
        ReportedBy: braddr puremagic.com


Issues with the code that follows.

1) Both "if" statements in the foreach in main crash DMD.  They can be
commented
in any way as long as they're not commented together and they'll crash.

2) If you uncomment the "exists" function declaration (that is currently
commented) and comment the one below it, DMD will crash.

I could just be using templates incorrectly here, but in either case, it's a
bug
that DMD crashes.

I'm using Win2k, DMD 0.149.

:void main() {
:    char[][] result, test;
:    
:    foreach (x; test) {
:        if (exists!(char[][], char[])(result, x) == true) {
:            return true;
:        }
:        if (exists(result, x) == true) {
:            return true;
:        }
:    }
:}

:template exists(T, U) {
:    //bool exists(T[][] src, U[] test) {
:    bool exists(T src, U test) {
:        foreach (x; src) {
:            if (x == test) {
:                return true;
:            }
:        }
:        
:        return false;
:    }
:}

-Kramer


-- 
Mar 12 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=38


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |ice-on-invalid-code, ice-on-
                   |                            |valid-code





Let me try to make sense of this:

- The code as it is crashes DMD.
- If you comment out one of the if statements, then it still crashes DMD.
- If you comment out both of the if statements, then it doesn't crash.
- If you replace the function signature of exists with the one that's commented
out, then, in the same way, DMD crashes as long as at least one of the if
statements is active.

But your code seems valid in most cases.

With exists(T, U), it's instantiated as exists!(char[][], char[]).  
With exists(T[][], U[]), it's instantiated as exists!(char, char).

The first if statement is valid for exists(T, U), but not for exists(T[][],
U[]).


-- 
May 18 2006