C++ guys hate static_if?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 11 15:06:07 PDT 2013


On Mon, Mar 11, 2013 at 10:31:53PM +0100, Timon Gehr wrote:
> On 03/11/2013 09:19 PM, Jonathan M Davis wrote:
> >On Monday, March 11, 2013 20:14:07 Timon Gehr wrote:
> >>Actually, in D, static if creates its own scopes for declarations
> >>made inside the static if condition.
> >
> >No, it doesn't,
> 
> Yes it does.

Actually, it doesn't, scarily enough:

	import std.stdio;
	void main() {
		int[string] x;
		//float x;
		static if (is(typeof(x) S : T[U], T, U)) {
			writeln(S.stringof);
			writeln(T.stringof);
			writeln(U.stringof);
		}
		writeln(S.stringof); // <-- this compiles, and works!!
	}

The last writeln will fail to compile if x's type is changed to float
(as in the commented out line).

Meaning that the definitions of S, T, U "leak" past the scope of the
static if. Which makes the semantics of the code very unclear, because
whether or not it even compiles depends on how the static if condition
turns out. :-/


T

-- 
Trying to define yourself is like trying to bite your own teeth. -- Alan Watts


More information about the Digitalmars-d mailing list