D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1820 - Let ifti see through static if condition in some cases
Summary: Let ifti see through static if condition in some cases
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2008-02-07 17:11 UTC by Andrei Alexandrescu
Modified: 2020-03-21 03:56 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2008-02-07 17:11:17 UTC
The following code compiles and runs as expected:

import std.stdio;

template wyda(string pred = ``)
{
    void wyda(int x) { writeln(pred, " ", x); }
}

void main()
{
    wyda(3);
    wyda!("a")(4);
}

However, the following equivalent code does not:

import std.stdio;

template wyda(string pred = ``)
{
    static if (true)
        void wyda(int x) { writeln(pred, " ", x); }
}

void main()
{
    wyda(3);
    wyda!("a")(4);
}

The proposed solution is to get rid to the maximum extent possible of the requirements for the noisy "!()" syntax. If a template name is specified without the "!", then it should simply assume "!()" followed.


Andrei
Comment 1 yebblies 2011-07-02 21:28:33 UTC
The issue here is in:

template func(T)
{
    static if (cond)
        void func(T x) {}
}

func is only a function template (onemember) when cond is true, and in the general case cond may rely on T, which relies on ifti.

The following might illustrate it better:

template func(T)
{
    static if (is(T == int)) // how could we know this before performing ifti?
        void func(T* x) {}
}

The compiler cannot generally evaluate static if conditions without the template args being known.  Although it could in very simple cases, I'm not sure it's worth the effort.

One place I think this could be done is inside VersionConditions.
Comment 2 Simen Kjaeraas 2017-09-19 11:50:41 UTC
Code in this issue compiles and runs correctly on 2.075.1.