www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is this a bug? `static if` fails silently.

reply "Meta" <jared771 gmail.com> writes:
struct Test(T)
{
	static if (is(typeof(T) == int))
	{
		pragma(msg, "test");
		
		this(T t)
		{
			this.t = t;
		}
	}
}

void main()
{
         //Nothing is printed
	Test!int t;
}

Didn't this code used to failed at the point of `typeof(T)`? Has 
this changed since previous releases?
Nov 04 2014
next sibling parent reply "deadalnix" <deadalnix gmail.com> writes:
On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
 struct Test(T)
 {
 	static if (is(typeof(T) == int))
 	{
 		pragma(msg, "test");
 		
 		this(T t)
 		{
 			this.t = t;
 		}
 	}
 }

 void main()
 {
         //Nothing is printed
 	Test!int t;
 }

 Didn't this code used to failed at the point of `typeof(T)`? 
 Has this changed since previous releases?
It is not static if, it is is. Is is defined as false for invalid types.
Nov 04 2014
next sibling parent "Meta" <jared771 gmail.com> writes:
On Tuesday, 4 November 2014 at 09:07:10 UTC, deadalnix wrote:
 It is not static if, it is is. Is is defined as false for 
 invalid types.
Ah, right. That's annoyingly hard to spot, but it is not a bug I suppose.
Nov 04 2014
prev sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Tuesday, 4 November 2014 at 09:07:10 UTC, deadalnix wrote:
 On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
 struct Test(T)
 {
 	static if (is(typeof(T) == int))
 	{
 		pragma(msg, "test");
 		
 		this(T t)
 		{
 			this.t = t;
 		}
 	}
 }

 void main()
 {
        //Nothing is printed
 	Test!int t;
 }

 Didn't this code used to failed at the point of `typeof(T)`? 
 Has this changed since previous releases?
It is not static if, it is is. Is is defined as false for invalid types.
a std.traits.TypeOf that errors out on non-types would be nice.
Nov 04 2014
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Tuesday, 4 November 2014 at 09:54:44 UTC, John Colvin wrote:
 On Tuesday, 4 November 2014 at 09:07:10 UTC, deadalnix wrote:
 On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
 struct Test(T)
 {
 	static if (is(typeof(T) == int))
 	{
 		pragma(msg, "test");
 		
 		this(T t)
 		{
 			this.t = t;
 		}
 	}
 }

 void main()
 {
       //Nothing is printed
 	Test!int t;
 }

 Didn't this code used to failed at the point of `typeof(T)`? 
 Has this changed since previous releases?
It is not static if, it is is. Is is defined as false for invalid types.
a std.traits.TypeOf that errors out on non-types would be nice.
woops, ignore me.
Nov 04 2014
prev sibling parent reply "Tofu Ninja" <emmons0 purdue.edu> writes:
On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:

 typeof(T)
What is the type of a type?
Nov 04 2014
parent "Meta" <jared771 gmail.com> writes:
On Tuesday, 4 November 2014 at 21:20:59 UTC, Tofu Ninja wrote:
 On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:

 typeof(T)
What is the type of a type?
A kind, of course. =)
Nov 04 2014