D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6879 - The difference of between template matching and IsExp
Summary: The difference of between template matching and IsExp
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-11-02 04:57 UTC by Kenji Hara
Modified: 2011-11-14 22:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2011-11-02 04:57:00 UTC
I think following code should compile.

----
private template isStaticArray(T : U[N], U, size_t N)
{
    enum bool isStaticArray = true;
}
private template isStaticArray(T)
{
    enum bool isStaticArray = false;
}

void main()
{
    alias int[3] T;

    enum res1 = isStaticArray!T;

    static if (is(T _ : U[N], U, size_t N))
        enum res2 = true;
    else
        enum res2 = false;

    static assert(res1 == res2);   // fails... Why?
}
Comment 1 Kenji Hara 2011-11-02 06:00:41 UTC
When static if condition is same as follows, the judgement succeeds.

    static if (is(T _ : X, X : U[N], U, size_t N))
        ...

This works as expected, but unneeded two symbols require (_ and X).
It seems to me that this syntax has little confusing.
Comment 2 Kenji Hara 2011-11-02 07:44:11 UTC
I have found the true issue.

alias int[3] T;
static if (is(T _ : U[N], U, int N))      // a: match
static if (is(T _ : U[N], U, uint N))     // b: match
static if (is(T _ : U[N], U, size_t N))   // c: doesn't match

The mismatching of c is 'rejects-valid' issue IMO.